KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > in > co > daffodil > db > jdbc > DaffodilDBStatement


1 package in.co.daffodil.db.jdbc;
2
3 import java.sql.*;
4 import java.util.*;
5 import com.daffodilwoods.daffodildb.client.*;
6 import com.daffodilwoods.database.resource.*;
7 import com.daffodilwoods.daffodildb.server.sql99.dql.listenerevents.*;
8 import com.daffodilwoods.daffodildb.server.sql99.dml.DMLResult;
9 import com.daffodilwoods.daffodildb.server.serversystem._Connection;
10 import com.daffodilwoods.daffodildb.server.datadictionarysystem._ColumnCharacteristics;
11
12 /**
13  * <P>The object used for executing a static SQL statement
14  * and returning the results it produces.
15  * <P>
16  * By default, only one <code>ResultSet</code> object per <code>Statement</code>
17  * object can be open at the same time. Therefore, if the reading of one
18  * <code>ResultSet</code> object is interleaved
19  * with the reading of another, each must have been generated by
20  * different <code>Statement</code> objects. All execution methods in the
21  * <code>Statement</code> interface implicitly close a statment's current
22  * <code>ResultSet</code> object if an open one exists.
23  *
24  * @see Connection#createStatement
25  * @see ResultSet
26  *
27  * <br><br>
28  * <B>Last Updated </B>
29  * <U> Dec. 20,2004 </U><br>
30  * <I>Purpose :To provide method synchronization . </I><br>
31  * <B>Author</B> Manoj Kr. Sheoran<br>
32
33  */

34 public class DaffodilDBStatement
35     implements Statement {
36
37   int fetchSize;
38   int fetchDirection;
39   int resultSetType;
40   int resultSetConcurrency;
41   int resultSetHoldability;
42   int maxFieldSize;
43   int maxRows;
44   int queryTimeOut;
45
46   DaffodilDBConnection connection;
47   ArrayList batchList;
48   Object JavaDoc[] executeResult;
49   int currentResultIndex;
50   SQLWarning sqlWarnings;
51   int updateCount;
52   DaffodilDBResultSet resultSet;
53   boolean escapeProcessingEnabled;
54   Locale locale;
55   DMLResult dmlResult;
56
57   public DaffodilDBStatement(DaffodilDBConnection connection) throws
58       SQLException {
59     this(connection,
60          ResultSet.TYPE_FORWARD_ONLY,
61          ResultSet.CONCUR_READ_ONLY,
62          1 /*ResultSet.HOLD_CURSORS_OVER_COMMIT*/);
63   }
64
65   public DaffodilDBStatement(DaffodilDBConnection connection,
66                              int resultSetType,
67                              int resultSetConcurrency) throws SQLException {
68     this(connection,
69          resultSetType,
70          resultSetConcurrency,
71          1 /*ResultSet.HOLD_CURSORS_OVER_COMMIT*/);
72   }
73
74   public DaffodilDBStatement(DaffodilDBConnection connection,
75                              int resultSetType,
76                              int resultSetConcurrency,
77                              int resultSetHoldability) throws SQLException {
78     locale = connection.getLocale();
79     if (!connection.getMetaData().supportsResultSetType(resultSetType)) {
80       addWarning("DataBaseMetaData does not supports passed ResultSetType");
81       resultSetType = ResultSet.TYPE_FORWARD_ONLY;
82     }
83     if (!connection.getMetaData().supportsResultSetConcurrency(resultSetType,
84         resultSetConcurrency)) {
85       addWarning("DataBaseMetaData does not supports passed Concurrency");
86       resultSetConcurrency = ResultSet.CONCUR_READ_ONLY;
87     }
88     this.connection = connection;
89     this.resultSetType = resultSetType;
90     this.resultSetConcurrency = resultSetConcurrency;
91     this.resultSetHoldability = resultSetHoldability;
92     fetchDirection = ResultSet.FETCH_FORWARD;
93     escapeProcessingEnabled = true;
94     queryTimeOut = 0;
95   }
96
97   protected void writeToLog(String JavaDoc str) {
98     DaffodilDBConnection.println(str);
99   }
100
101   protected void writeToLog(String JavaDoc modifier,String JavaDoc str) {
102      DaffodilDBConnection.println(modifier,str);
103    }
104
105   /**
106    * Executes the given SQL s tatement, which returns a single
107    * <code>ResultSet</code> object.
108    *
109    * @param sql an SQL statement to be sent to the database, typically a
110    * static SQL <code>SELECT</code> statement
111    * @return a <code>ResultSet</code> object that contains the data produced
112    * by the given query; never <code>null</code>
113    * @exception SQLException if a database access error occurs or the given
114    * SQL statement produces anything other than a single
115    * <code>ResultSet</code> object
116    */

117
118   public synchronized ResultSet executeQuery(String JavaDoc query) throws SQLException {
119     checkConnection();
120     if (query == null || query.length() == 0) {
121       DException dex = new DException("DSE828", null);
122       throw dex.getSqlException(locale);
123     }
124     writeToLog("Query" , query);
125     createEnvironmentToExecute(true);
126     if (resultSet != null) {
127       resultSet.close();
128       resultSet = null;
129     }
130     updateCount = -1;
131
132     String JavaDoc queryForDB = escapeProcessingEnabled ? connection.nativeSQL(query) :
133         query;
134     Object JavaDoc result[] = null;
135     try {
136       synchronized (connection) {
137         result = getRequiredObjectOfexecuteQuery(
138             connection.getServerConnection().executeQuery(queryForDB,
139             queryTimeOut,
140             resultSetConcurrency == ResultSet.CONCUR_UPDATABLE ?
141                                             IteratorConstants.UPDATABLE :
142                                             IteratorConstants.NONSCROLLABLE),
143                                             resultSetConcurrency,maxRows);
144       }
145     }
146     catch (DException dse) {
147       throw dse.getSqlException(connection.getLocale());
148     }
149
150     _RecordSetBuffer rsb = (_RecordSetBuffer) result[0];
151     resultSet = new DaffodilDBResultSet(this);
152     resultSet.setRecordSetBuffer(rsb);
153     int oldResultSetCon = resultSetConcurrency;
154     resultSetConcurrency = result[1].hashCode();
155     if(oldResultSetCon != resultSetConcurrency ){
156       addWarning("the resultSet Concurency is set ResultSet.CONCUR_READ_ONLY ");
157     }
158     setResultSetAttributes();
159     setRecordSetBufferAttributes(rsb);
160     resultSetConcurrency = oldResultSetCon;
161     return resultSet;
162   }
163
164   /**
165    * Executes the given SQL statement, which may be an <code>INSERT</code>,
166    * <code>UPDATE</code>, or <code>DELETE</code> statement or an
167    * SQL statement that returns nothing, such as an SQL DDL statement.
168    *
169    * @param sql an SQL <code>INSERT</code>, <code>UPDATE</code> or
170    * <code>DELETE</code> statement or an SQL statement that returns nothing
171    * @return either the row count for <code>INSERT</code>, <code>UPDATE</code>
172    * or <code>DELETE</code> statements, or <code>0</code> for SQL statements
173    * that return nothing
174    * @exception SQLException if a database access error occurs or the given
175    * SQL statement produces a <code>ResultSet</code> object
176    */

177
178   public synchronized int executeUpdate(String JavaDoc query) throws SQLException {
179     return executeUpdate(query, true);
180   }
181
182   /**
183    * Releases this <code>Statement</code> object's database
184    * and JDBC resources immediately instead of waiting for
185    * this to happen when it is automatically closed.
186    * It is generally good practice to release resources as soon as
187    * you are finished with them to avoid tying up database
188    * resources.
189    * <P>
190    * Calling the method <code>close</code> on a <code>Statement</code>
191    * object that is already closed has no effect.
192    * <P>
193    * <B>Note:</B> A <code>Statement</code> object is automatically closed
194    * when it is garbage collected. When a <code>Statement</code> object is
195    * closed, its current <code>ResultSet</code> object, if one exists, is
196    * also closed.
197    *
198    * @exception SQLException if a database access error occurs
199    *
200    * @ todo
201    * what about ResultSet
202    * override finalize method and call close from there
203    * <P><B>Note:</B> A <code>Statement</code> object is automatically closed when it is
204        * garbage collected. When a <code>Statement</code> object is closed, its current
205    * <code>ResultSet</code> object, if one exists, is also closed.
206    */

207
208   public synchronized void close() throws SQLException {
209     if (resultSet != null)
210        synchronized( resultSet){
211          resultSet.close();
212        }
213    connection = null;
214   }
215
216
217   /**
218    * Retrieves the maximum number of bytes that can be
219        * returned for character and binary column values in a <code>ResultSet</code>
220    * object produced by this <code>Statement</code> object.
221    * This limit applies only to <code>BINARY</code>,
222    * <code>VARBINARY</code>, <code>LONGVARBINARY</code>, <code>CHAR</code>,
223    * <code>VARCHAR</code>, and <code>LONGVARCHAR</code>
224    * columns. If the limit is exceeded, the excess data is silently
225    * discarded.
226    *
227    * @return the current column size limit for columns storing character and
228    * binary values; zero means there is no limit
229    * @exception SQLException if a database access error occurs
230    * @see #setMaxFieldSize
231    *
232    * @ todo maxFieldSize
233    * To be passed to session/resultset
234    */

235
236   public synchronized int getMaxFieldSize() throws SQLException {
237     checkConnection();
238     return maxFieldSize;
239   }
240
241   /**
242    * Sets the limit for the maximum number of bytes in a <code>ResultSet</code>
243    * column storing character or binary values to
244    * the given number of bytes. This limit applies
245    * only to <code>BINARY</code>, <code>VARBINARY</code>,
246    * <code>LONGVARBINARY</code>, <code>CHAR</code>, <code>VARCHAR</code>, and
247        * <code>LONGVARCHAR</code> fields. If the limit is exceeded, the excess data
248    * is silently discarded. For maximum portability, use values
249    * greater than 256.
250    *
251        * @param max the new column size limit in bytes; zero means there is no limit
252    * @exception SQLException if a database access error occurs
253    * or the condition max >= 0 is not satisfied
254    * @see #getMaxFieldSize
255    */

256
257   public synchronized void setMaxFieldSize(int max) throws SQLException {
258     checkConnection();
259     if (max < 0) {
260       DException dex = new DException("DSE828", null);
261       throw dex.getSqlException(locale);
262     }
263     maxFieldSize = max;
264   }
265
266   /**
267    * Retrieves the maximum number of rows that a
268    * <code>ResultSet</code> object produced by this
269    * <code>Statement</code> object can contain. If this limit is exceeded,
270    * the excess rows are silently dropped.
271    *
272    * @return the current maximum number of rows for a <code>ResultSet</code>
273    * object produced by this <code>Statement</code> object;
274    * zero means there is no limit
275    * @exception SQLException if a database access error occurs
276    * @see #setMaxRows
277    *
278    * @ todo maxRows
279    * To be passed to session/resultset
280    */

281
282   public synchronized int getMaxRows() throws SQLException {
283     checkConnection();
284     return maxRows;
285   }
286
287   /**
288    * Sets the limit for the maximum number of rows that any
289    * <code>ResultSet</code> object can contain to the given number.
290    * If the limit is exceeded, the excess
291    * rows are silently dropped.
292    *
293    * @param max the new max rows limit; zero means there is no limit
294    * @exception SQLException if a database access error occurs
295    * or the condition max >= 0 is not satisfied
296    * @see #getMaxRows
297    */

298
299   public synchronized void setMaxRows(int max) throws SQLException {
300     checkConnection();
301     if (max < 0) {
302       DException dex = new DException("DSE545", new Object JavaDoc[] {new Integer JavaDoc(max)});
303       throw dex.getSqlException(locale);
304     }
305     maxRows = max;
306   }
307
308   /**
309    * Sets escape processing on or off.
310    * If escape scanning is on (the default), the driver will do
311    * escape substitution before sending the SQL statement to the database.
312    *
313    * Note: Since prepared statements have usually been parsed prior
314    * to making this call, disabling escape processing for
315    * <code>PreparedStatements</code> objects will have no effect.
316    *
317    * @param enable <code>true</code> to enable escape processing;
318    * <code>false</code> to disable it
319    * @exception SQLException if a database access error occurs
320    *
321    */

322
323   public synchronized void setEscapeProcessing(boolean enable) throws SQLException {
324     checkConnection();
325     escapeProcessingEnabled = enable;
326   }
327
328   /**
329    * Retrieves the number of seconds the driver will
330    * wait for a <code>Statement</code> object to execute. If the limit is exceeded, a
331    * <code>SQLException</code> is thrown.
332    *
333    * @return the current query timeout limit in seconds; zero means there is
334    * no limit
335    * @exception SQLException if a database access error occurs
336    * @see #setQueryTimeout
337    */

338
339   public synchronized int getQueryTimeout() throws SQLException {
340     checkConnection();
341     return queryTimeOut;
342   }
343
344   /**
345    * Sets the number of seconds the driver will wait for a
346    * <code>Statement</code> object to execute to the given number of seconds.
347    * If the limit is exceeded, an <code>SQLException</code> is thrown.
348    *
349    * @param seconds the new query timeout limit in seconds; zero means
350    * there is no limit
351    * @exception SQLException if a database access error occurs
352    * or the condition seconds >= 0 is not satisfied
353    * @see #getQueryTimeout
354    *
355    * @ todo setQueryTimeout
356    * To be passed to session in execute
357    */

358
359   public synchronized void setQueryTimeout(int seconds) throws SQLException {
360     checkConnection();
361     if (seconds < 0) {
362       DException dex = new DException("DSE832",
363                                       new Object JavaDoc[] {new Integer JavaDoc(seconds)});
364       throw dex.getSqlException(locale);
365     }
366     queryTimeOut = seconds;
367   }
368
369   /**
370    * Cancels this <code>Statement</code> object if both the DBMS and
371    * driver support aborting an SQL statement.
372    * This method can be used by one thread to cancel a statement that
373    * is being executed by another thread.
374    *
375    * @exception SQLException if a database access error occurs
376    * @ todo
377    * to be implemented
378    */

379
380   public synchronized void cancel() throws SQLException {
381     DException dex = new DException("DSE16", new Object JavaDoc[] {"cancel"});
382     throw dex.getSqlException(locale);
383   }
384
385   /**
386    * Retrieves the first warning reported by calls on this <code>Statement</code> object.
387    * Subsequent <code>Statement</code> object warnings will be chained to this
388    * <code>SQLWarning</code> object.
389    *
390    * <p>The warning chain is automatically cleared each time
391    * a statement is (re)executed. This method may not be called on a closed
392    * <code>Statement</code> object; doing so will cause an <code>SQLException</code>
393    * to be thrown.
394    *
395    * <P><B>Note:</B> If you are processing a <code>ResultSet</code> object, any
396    * warnings associated with reads on that <code>ResultSet</code> object
397    * will be chained on it rather than on the <code>Statement</code>
398    * object that produced it.
399    *
400    * @return the first <code>SQLWarning</code> object or <code>null</code>
401    * if there are no warnings
402    * @exception SQLException if a database access error occurs or this
403    * method is called on a closed statement
404    */

405
406   public synchronized SQLWarning getWarnings() throws SQLException {
407     checkConnection();
408     return sqlWarnings;
409   }
410
411   /**
412    * Clears all the warnings reported on this <code>Statement</code>
413    * object. After a call to this method,
414    * the method <code>getWarnings</code> will return
415    * <code>null</code> until a new warning is reported for this
416    * <code>Statement</code> object.
417    *
418    * @exception SQLException if a database access error occurs
419    * @ todo
420    * SqlWarning object is cleared whenever a statement is (re)executed.
421    * And this is not the connection warning
422    */

423
424   public synchronized void clearWarnings() throws SQLException {
425     checkConnection();
426     sqlWarnings = null;
427   }
428
429   /**
430    * Sets the SQL cursor name to the given <code>String</code>, which
431    * will be used by subsequent <code>Statement</code> object
432    * <code>execute</code> methods. This name can then be
433    * used in SQL positioned update or delete statements to identify the
434    * current row in the <code>ResultSet</code> object generated by this
435    * statement. If the database does not support positioned update/delete,
436    * this method is a noop. To insure that a cursor has the proper isolation
437    * level to support updates, the cursor's <code>SELECT</code> statement
438    * should have the form <code>SELECT FOR UPDATE</code>. If
439    * <code>FOR UPDATE</code> is not present, positioned updates may fail.
440    *
441    * <P><B>Note:</B> By definition, the execution of positioned updates and
442    * deletes must be done by a different <code>Statement</code> object than
443    * the one that generated the <code>ResultSet</code> object being used for
444    * positioning. Also, cursor names must be unique within a connection.
445    *
446    * @param name the new cursor name, which must be unique within
447    * a connection
448    * @exception SQLException if a database access error occurs
449    * @ todo setCursorName
450    * Low Priority. If they are supporting this do it otherwise left
451    * as such.
452    */

453
454   public synchronized void setCursorName(String JavaDoc name) throws SQLException {
455     checkConnection();
456     DException dex = new DException("DSE16", new Object JavaDoc[] {"setCursorName"});
457     throw dex.getSqlException(locale);
458   }
459
460
461   /**
462    * Executes the given SQL statement, which may return multiple results.
463    * In some (uncommon) situations, a single SQL statement may return
464    * multiple result sets and/or update counts. Normally you can ignore
465    * this unless you are (1) executing a stored procedure that you know may
466    * return multiple results or (2) you are dynamically executing an
467    * unknown SQL string.
468    * <P>
469        * The <code>execute</code> method executes an SQL statement and indicates the
470    * form of the first result. You must then use the methods
471    * <code>getResultSet</code> or <code>getUpdateCount</code>
472    * to retrieve the result, and <code>getMoreResults</code> to
473    * move to any subsequent result(s).
474    *
475    * @param sql any SQL statement
476    * @return <code>true</code> if the first result is a <code>ResultSet</code>
477    * object; <code>false</code> if it is an update count or there are
478    * no results
479    * @exception SQLException if a database access error occurs
480    * @see #getResultSet
481    * @see #getUpdateCount
482    * @see #getMoreResults
483    *
484    * @todo holdability
485    * Should check for holdability
486    */

487
488   public synchronized boolean execute(String JavaDoc query) throws SQLException {
489     checkConnection();
490     writeToLog(query);
491     if (query == null || query.length() == 0) {
492       DException dex = new DException("DSE828", null);
493       throw dex.getSqlException(locale);
494     }
495     createEnvironmentToExecute(true);
496     if (resultSet != null) {
497       resultSet.close();
498       resultSet = null;
499     }
500     currentResultIndex = 0;
501     updateCount = -1;
502
503     String JavaDoc queryForDB = changeQueryForDB(query);
504     Object JavaDoc[] reqObject = null;
505     try {
506     synchronized (connection) {
507         executeResult = new Object JavaDoc[] {
508             connection.getServerConnection().execute(queryForDB, queryTimeOut, resultSetConcurrency == ResultSet.CONCUR_UPDATABLE ?
509                                             IteratorConstants.UPDATABLE :
510                                             IteratorConstants.NONSCROLLABLE)};
511       }
512
513       reqObject = getRequiredObjectOfexecute(executeResult[0],
514           resultSetConcurrency,maxRows);
515       executeResult[0] = reqObject[0];
516     }
517     catch (DException dex) {
518
519       throw dex.getSqlException(connection.getLocale());
520     }
521
522     if (executeResult[0] instanceof _RecordSetBuffer) {
523       _RecordSetBuffer rsb = (_RecordSetBuffer) executeResult[0];
524       resultSet = new DaffodilDBResultSet(this);
525       resultSet.setRecordSetBuffer(rsb);
526       int oldResultSetCon = resultSetConcurrency;
527       resultSetConcurrency = reqObject[1].hashCode();
528       if(oldResultSetCon != resultSetConcurrency )
529         addWarning("the resultSet Concurency is set ResultSet.CONCUR_READ_ONLY " ) ;
530       setResultSetAttributes();
531       setRecordSetBufferAttributes(rsb);
532       resultSetConcurrency = oldResultSetCon;
533       return true;
534     }
535     updateCount = executeResult[0].hashCode();
536     updateCount = updateCount == Integer.MIN_VALUE ? 0 : updateCount;
537     return false;
538   }
539
540   /**
541    * Retrieves the current result as a <code>ResultSet</code> object.
542    * This method should be called only once per result.
543    *
544    * @return the current result as a <code>ResultSet</code> object or
545    * <code>null</code> if the result is an update count or there are no more results
546    * @exception SQLException if a database access error occurs
547    * @see #execute
548    */

549
550   public synchronized ResultSet getResultSet() throws SQLException {
551     checkConnection();
552     return resultSet;
553   }
554
555   /**
556    * Retrieves the current result as an update count;
557    * if the result is a <code>ResultSet</code> object or there are no more results, -1
558    * is returned. This method should be called only once per result.
559    *
560        * @return the current result as an update count; -1 if the current result is a
561    * <code>ResultSet</code> object or there are no more results
562    * @exception SQLException if a database access error occurs
563    * @see #execute
564    */

565
566   public synchronized int getUpdateCount() throws SQLException {
567     checkConnection();
568     return updateCount;
569   }
570
571   /**
572    * Moves to this <code>Statement</code> object's next result, returns
573    * <code>true</code> if it is a <code>ResultSet</code> object, and
574    * implicitly closes any current <code>ResultSet</code>
575    * object(s) obtained with the method <code>getResultSet</code>.
576    *
577    * <P>There are no more results when the following is true:
578    * <PRE>
579    * <code>(!getMoreResults() && (getUpdateCount() == -1)</code>
580    * </PRE>
581    *
582    * @return <code>true</code> if the next result is a <code>ResultSet</code>
583    * object; <code>false</code> if it is an update count or there are
584    * no more results
585    * @exception SQLException if a database access error occurs
586    * @see #execute
587    */

588
589   public synchronized boolean getMoreResults() throws SQLException {
590     checkConnection();
591     currentResultIndex++;
592     if (executeResult != null && currentResultIndex < executeResult.length) {
593       if (resultSet != null) {
594         resultSet.close();
595         resultSet = null;
596       }
597       updateCount = -1;
598       if (executeResult[currentResultIndex] instanceof _RecordSetBuffer) {
599         _RecordSetBuffer rsb = (_RecordSetBuffer) executeResult[
600             currentResultIndex];
601         resultSet = new DaffodilDBResultSet(this);
602         resultSet.setRecordSetBuffer(rsb);
603         setResultSetAttributes();
604         setRecordSetBufferAttributes(rsb);
605         return true;
606       }
607       updateCount = executeResult[currentResultIndex].hashCode();
608       updateCount = updateCount == Integer.MIN_VALUE ? 0 : updateCount;
609       return false;
610     }
611     if (resultSet != null) {
612       resultSet.close();
613       resultSet = null;
614     }
615     executeResult = null;
616     updateCount = -1;
617     return false;
618   }
619
620
621   /**
622    * Gives the driver a hint as to the direction in which
623    * rows will be processed in <code>ResultSet</code>
624    * objects created using this <code>Statement</code> object. The
625    * default value is <code>ResultSet.FETCH_FORWARD</code>.
626    * <P>
627    * Note that this method sets the default fetch direction for
628    * result sets generated by this <code>Statement</code> object.
629    * Each result set has its own methods for getting and setting
630    * its own fetch direction.
631    *
632    * @param direction the initial direction for processing rows
633    * @exception SQLException if a database access error occurs
634    * or the given direction
635    * is not one of <code>ResultSet.FETCH_FORWARD</code>,
636        * <code>ResultSet.FETCH_REVERSE</code>, or <code>ResultSet.FETCH_UNKNOWN</code>
637    * @since 1.2
638    * @see #getFetchDirection
639    *
640    * @ todo fetchDirection
641    *
642    */

643
644   public synchronized void setFetchDirection(int direction) throws SQLException {
645     checkConnection();
646     if (direction == ResultSet.FETCH_FORWARD ||
647         direction == ResultSet.FETCH_REVERSE ||
648         direction == ResultSet.FETCH_UNKNOWN)
649       fetchDirection = direction;
650     else {
651       DException dex = new DException("DSE541",
652                                       new Object JavaDoc[] {new Integer JavaDoc(direction)});
653       throw dex.getSqlException(locale);
654     }
655   }
656
657   /**
658    * Retrieves the direction for fetching rows from
659    * database tables that is the default for result sets
660    * generated from this <code>Statement</code> object.
661    * If this <code>Statement</code> object has not set
662    * a fetch direction by calling the method <code>setFetchDirection</code>,
663    * the return value is implementation-specific.
664    *
665    * @return the default fetch direction for result sets generated
666    * from this <code>Statement</code> object
667    * @exception SQLException if a database access error occurs
668    * @since 1.2
669    * @see #setFetchDirection
670    */

671
672   public synchronized int getFetchDirection() throws SQLException {
673     checkConnection();
674     return fetchDirection;
675   }
676
677   /**
678    * Gives the JDBC driver a hint as to the number of rows that should
679    * be fetched from the database when more rows are needed. The number
680    * of rows specified affects only result sets created using this
681    * statement. If the value specified is zero, then the hint is ignored.
682    * The default value is zero.
683    *
684    * @param rows the number of rows to fetch
685    * @exception SQLException if a database access error occurs, or the
686    * condition 0 <= <code>rows</code> <= <code>this.getMaxRows()</code>
687    * is not satisfied.
688    * @since 1.2
689    * @see #getFetchSize
690    * @ todo
691    * should throw SQLException if a database access error occurs, or the
692    * condition 0 <= rows <= this.getMaxRows() is not satisfied.
693    */

694
695   public synchronized void setFetchSize(int rows) throws SQLException {
696     checkConnection();
697     if (rows < 0 || (getMaxRows() != 0 && rows > getMaxRows())) {
698       DException dex = new DException("DSE518", new Object JavaDoc[] {new Integer JavaDoc(rows)});
699       throw dex.getSqlException(locale);
700     }
701     fetchSize = rows;
702   }
703
704   /**
705    * Retrieves the number of result set rows that is the default
706    * fetch size for <code>ResultSet</code> objects
707    * generated from this <code>Statement</code> object.
708    * If this <code>Statement</code> object has not set
709    * a fetch size by calling the method <code>setFetchSize</code>,
710    * the return value is implementation-specific.
711    *
712    * @return the default fetch size for result sets generated
713    * from this <code>Statement</code> object
714    * @exception SQLException if a database access error occurs
715    * @since 1.2
716    * @see #setFetchSize
717    */

718
719   public synchronized int getFetchSize() throws SQLException {
720     checkConnection();
721     return fetchSize;
722   }
723
724   /**
725    * Retrieves the result set concurrency for <code>ResultSet</code> objects
726    * generated by this <code>Statement</code> object.
727    *
728    * @return either <code>ResultSet.CONCUR_READ_ONLY</code> or
729    * <code>ResultSet.CONCUR_UPDATABLE</code>
730    * @exception SQLException if a database access error occurs
731    * @since 1.2
732    */

733
734   public synchronized int getResultSetConcurrency() throws SQLException {
735     checkConnection();
736     return resultSetConcurrency;
737   }
738
739   /**
740    * Retrieves the result set type for <code>ResultSet</code> objects
741    * generated by this <code>Statement</code> object.
742    *
743    * @return one of <code>ResultSet.TYPE_FORWARD_ONLY</code>,
744    * <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
745    * <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
746    * @exception SQLException if a database access error occurs
747    * @since 1.2
748    */

749
750   public synchronized int getResultSetType() throws SQLException {
751     checkConnection();
752     return resultSetType;
753   }
754
755   /**
756    * Adds the given SQL command to the current list of commmands for this
757    * <code>Statement</code> object. The commands in this list can be
758    * executed as a batch by calling the method <code>executeBatch</code>.
759    * <P>
760    * <B>NOTE:</B> This method is optional.
761    *
762    * @param sql typically this is a static SQL <code>INSERT</code> or
763    * <code>UPDATE</code> statement
764    * @exception SQLException if a database access error occurs, or the
765    * driver does not support batch updates
766    * @see #executeBatch
767    * @since 1.2
768    */

769
770   public synchronized void addBatch(String JavaDoc sql) throws SQLException {
771     checkConnection();
772     if (batchList == null)
773       batchList = new ArrayList();
774     batchList.add(sql);
775   }
776
777   /**
778    * Empties this <code>Statement</code> object's current list of
779    * SQL commands.
780    * <P>
781    * <B>NOTE:</B> This method is optional.
782    *
783    * @exception SQLException if a database access error occurs or the
784    * driver does not support batch updates
785    * @see #addBatch
786    * @since 1.2
787    */

788
789   public synchronized void clearBatch() throws SQLException {
790     checkConnection();
791     if (batchList != null && batchList.size() > 0)
792       batchList.clear();
793   }
794
795   /**
796    * Submits a batch of commands to the database for execution and
797    * if all commands execute successfully, returns an array of update counts.
798    * The <code>int</code> elements of the array that is returned are ordered
799    * to correspond to the commands in the batch, which are ordered
800    * according to the order in which they were added to the batch.
801    * The elements in the array returned by the method <code>executeBatch</code>
802    * may be one of the following:
803    * <OL>
804    * <LI>A number greater than or equal to zero -- indicates that the
805    * command was processed successfully and is an update count giving the
806    * number of rows in the database that were affected by the command's
807    * execution
808    * <LI>A value of <code>SUCCESS_NO_INFO</code> -- indicates that the command was
809    * processed successfully but that the number of rows affected is
810    * unknown
811    * <P>
812    * If one of the commands in a batch update fails to execute properly,
813    * this method throws a <code>BatchUpdateException</code>, and a JDBC
814    * driver may or may not continue to process the remaining commands in
815    * the batch. However, the driver's behavior must be consistent with a
816    * particular DBMS, either always continuing to process commands or never
817    * continuing to process commands. If the driver continues processing
818    * after a failure, the array returned by the method
819    * <code>BatchUpdateException.getUpdateCounts</code>
820    * will contain as many elements as there are commands in the batch, and
821    * at least one of the elements will be the following:
822    * <P>
823    * <LI>A value of <code>EXECUTE_FAILED</code> -- indicates that the command failed
824    * to execute successfully and occurs only if a driver continues to
825    * process commands after a command fails
826    * </OL>
827    * <P>
828    * A driver is not required to implement this method.
829    * The possible implementations and return values have been modified in
830    * the Java 2 SDK, Standard Edition, version 1.3 to
831    * accommodate the option of continuing to proccess commands in a batch
832    * update after a <code>BatchUpdateException</code> obejct has been thrown.
833    *
834    * @return an array of update counts containing one element for each
835    * command in the batch. The elements of the array are ordered according
836    * to the order in which commands were added to the batch.
837    * @exception SQLException if a database access error occurs or the
838        * driver does not support batch statements. Throws {@link BatchUpdateException}
839        * (a subclass of <code>SQLException</code>) if one of the commands sent to the
840    * database fails to execute properly or attempts to return a result set.
841    * @since 1.3
842    */

843
844   public synchronized int[] executeBatch() throws SQLException {
845     checkConnection();
846     if (batchList == null)
847       return new int[0]; // returning int array of size ZERO
848
writeToLog("Processing : DaffodilDBStatement.executeBatch()");
849     createEnvironmentToExecute(false);
850     int size = batchList.size();
851     int[] abc = new int[size];
852     Arrays.fill(abc, -3 /*EXECUTE_FAILED*/);
853     synchronized(connection){
854     for (int i = 0; i < size; i++) {
855       try {
856         abc[i] = executeUpdate( (String JavaDoc) batchList.get(i), false);
857       }
858       catch (SQLException E) {
859         clearBatch();
860         throw new BatchUpdateException(E.getMessage(), E.getSQLState(), abc);
861       }
862     }
863     }
864     clearBatch();
865     return abc;
866   }
867
868   /**
869    * Retrieves the <code>Connection</code> object
870    * that produced this <code>Statement</code> object.
871    * @return the connection that produced this statement
872    * @exception SQLException if a database access error occurs
873    * @since 1.2
874    */

875
876   public synchronized java.sql.Connection JavaDoc getConnection() throws SQLException {
877     checkConnection();
878     return connection;
879   }
880
881
882   /**
883    * The constant indicating that the current <code>ResultSet</code> object
884    * should be closed when calling <code>getMoreResults</code>.
885    *
886    * @since 1.4
887    */

888   /**
889    * The constant indicating that the current <code>ResultSet</code> object
890    * should not be closed when calling <code>getMoreResults</code>.
891    *
892    * @since 1.4
893    */

894   /**
895    * The constant indicating that all <code>ResultSet</code> objects that
896    * have previously been kept open should be closed when calling
897    * <code>getMoreResults</code>.
898    *
899    * @since 1.4
900    */

901   /**
902    * The constant indicating that a batch statement executed successfully
903    * but that no count of the number of rows it affected is available.
904    *
905    * @since 1.4
906    */

907   /**
908    * The constant indicating that an error occured while executing a
909    * batch statement.
910    *
911    * @since 1.4
912    */

913   /**
914    * The constant indicating that generated keys should be made
915    * available for retrieval.
916    *
917    * @since 1.4
918    */

919   /**
920    * The constant indicating that generated keys should not be made
921    * available for retrieval.
922    *
923    * @since 1.4
924    */

925   /**
926    * Moves to this <code>Statement</code> object's next result, deals with
927    * any current <code>ResultSet</code> object(s) according to the instructions
928    * specified by the given flag, and returns
929    * <code>true</code> if the next result is a <code>ResultSet</code> object.
930    *
931    * <P>There are no more results when the following is true:
932    * <PRE>
933    * <code>(!getMoreResults() && (getUpdateCount() == -1)</code>
934    * </PRE>
935    *
936    * @param current one of the following <code>Statement</code>
937    * constants indicating what should happen to current
938    * <code>ResultSet</code> objects obtained using the method
939    * <code>getResultSet</code:
940    * <code>CLOSE_CURRENT_RESULT</code>,
941    * <code>KEEP_CURRENT_RESULT</code>, or
942    * <code>CLOSE_ALL_RESULTS</code>
943    * @return <code>true</code> if the next result is a <code>ResultSet</code>
944    * object; <code>false</code> if it is an update count or there are no
945    * more results
946    * @exception SQLException if a database access error occurs
947    * @since 1.4
948    * @see #execute
949    */

950
951   public synchronized boolean getMoreResults(int current) throws SQLException {
952     checkConnection();
953     DException dex = new DException("DSE16",
954                                     new Object JavaDoc[] {"getMoreResults"});
955     throw dex.getSqlException(locale);
956   }
957
958   /**
959    * Retrieves any auto-generated keys created as a result of executing this
960    * <code>Statement</code> object. If this <code>Statement</code> object did
961    * not generate any keys, an empty <code>ResultSet</code>
962    * object is returned.
963    *
964        * @return a <code>ResultSet</code> object containing the auto-generated key(s)
965    * generated by the execution of this <code>Statement</code> object
966    * @exception SQLException if a database access error occurs
967    * @since 1.4
968    */

969
970   public synchronized ResultSet getGeneratedKeys() throws SQLException {
971     if(dmlResult == null || !dmlResult.isInitialised){
972       TempResultSet tempRs = new TempResultSet(new Object JavaDoc[0][0],new String JavaDoc[0]);
973       TempResultSetMetaData tempMetaData = new TempResultSetMetaData(new Object JavaDoc[0][20]);
974       tempRs.setType(ResultSet.TYPE_FORWARD_ONLY);
975       tempRs.setMetaData(tempMetaData);
976       return tempRs;
977     }
978     _ColumnCharacteristics cc = dmlResult.getColumnCharacteristics();
979     TempResultSet tempRs = null;
980     try {
981       tempRs = new TempResultSet(dmlResult.getAutoIncrementValues(), cc.getColumnNames());
982     }
983     catch (DException ex) {
984       throw ex.getSqlException(locale);
985     }
986     DaffodilDBResultSetMetaData rsmd = new DaffodilDBResultSetMetaData(connection);
987     rsmd.setColumnCharacteristics(cc);
988     tempRs.setType(ResultSet.TYPE_FORWARD_ONLY);
989     tempRs.setMetaData(rsmd);
990     return tempRs;
991   }
992
993   /**
994    * Executes the given SQL statement and signals the driver with the
995    * given flag about whether the
996    * auto-generated keys produced by this <code>Statement</code> object
997    * should be made available for retrieval.
998    *
999    * @param sql must be an SQL <code>INSERT</code>, <code>UPDATE</code> or
1000   * <code>DELETE</code> statement or an SQL statement that
1001   * returns nothing
1002   * @param autoGeneratedKeys a flag indicating whether auto-generated keys
1003   * should be made available for retrieval;
1004   * one of the following constants:
1005   * <code>Statement.RETURN_GENERATED_KEYS</code>
1006   * <code>Statement.NO_GENERATED_KEYS</code>
1007   * @return either the row count for <code>INSERT</code>, <code>UPDATE</code>
1008   * or <code>DELETE</code> statements, or <code>0</code> for SQL
1009   * statements that return nothing
1010   * @exception SQLException if a database access error occurs, the given
1011   * SQL statement returns a <code>ResultSet</code> object, or
1012   * the given constant is not one of those allowed
1013   * @since 1.4
1014   */

1015
1016  /** @todo Work to be done */
1017  public synchronized int executeUpdate(String JavaDoc sql, int autoGeneratedKeys) throws
1018      SQLException {
1019    if(autoGeneratedKeys == NO_GENERATED_KEYS)
1020      return executeUpdate(sql);
1021    writeToLog("Update" , sql + ", " + autoGeneratedKeys);
1022    return executeUpdate(sql,_Connection.AUTOGENERATEDKEYS,null);
1023  }
1024
1025  /**
1026   * Executes the given SQL statement and signals the driver that the
1027   * auto-generated keys indicated in the given array should be made available
1028   * for retrieval. The driver will ignore the array if the SQL statement
1029   * is not an <code>INSERT</code> statement.
1030   *
1031   * @param sql an SQL <code>INSERT</code>, <code>UPDATE</code> or
1032       * <code>DELETE</code> statement or an SQL statement that returns nothing,
1033   * such as an SQL DDL statement
1034   * @param columnIndexes an array of column indexes indicating the columns
1035   * that should be returned from the inserted row
1036   * @return either the row count for <code>INSERT</code>, <code>UPDATE</code>,
1037   * or <code>DELETE</code> statements, or 0 for SQL statements
1038   * that return nothing
1039   * @exception SQLException if a database access error occurs or the SQL
1040   * statement returns a <code>ResultSet</code> object
1041   * @since 1.4
1042   */

1043
1044  /** @todo Work to be done */
1045  public synchronized int executeUpdate(String JavaDoc sql, int columnIndexes[]) throws SQLException {
1046    checkConnection();
1047    if(columnIndexes == null){
1048      addWarning("NO Generated Keys will be retrived as, NO ColumnIndexes were passed");
1049      return executeUpdate(sql);
1050    }
1051    int length = columnIndexes.length;
1052    String JavaDoc str = " [";
1053    for (int i = 0; i < length; i++)
1054      str += (columnIndexes[i] + " ");
1055    writeToLog("Update" , sql + ", " + str);
1056    return executeUpdate(sql,_Connection.COLUMNINDEXES,columnIndexes);
1057  }
1058
1059  /**
1060   * Executes the given SQL statement and signals the driver that the
1061   * auto-generated keys indicated in the given array should be made available
1062   * for retrieval. The driver will ignore the array if the SQL statement
1063   * is not an <code>INSERT</code> statement.
1064   *
1065   * @param sql an SQL <code>INSERT</code>, <code>UPDATE</code> or
1066       * <code>DELETE</code> statement or an SQL statement that returns nothing
1067   * @param columnNames an array of the names of the columns that should be
1068   * returned from the inserted row
1069   * @return either the row count for <code>INSERT</code>, <code>UPDATE</code>,
1070   * or <code>DELETE</code> statements, or 0 for SQL statements
1071   * that return nothing
1072   * @exception SQLException if a database access error occurs
1073   *
1074   * @since 1.4
1075   */

1076
1077  /** @todo Work to be done */
1078  public synchronized int executeUpdate(String JavaDoc sql, String JavaDoc columnNames[]) throws
1079      SQLException {
1080    checkConnection();
1081    if(columnNames == null){
1082      addWarning("NO Generated Keys will be retrived as, NO ColumnIndexes were passed");
1083      return executeUpdate(sql);
1084    }
1085    int length = columnNames.length;
1086    String JavaDoc str = " [";
1087    for (int i = 0; i < length; i++)
1088      str += (columnNames[i] + " ");
1089    writeToLog("Update" , sql + ", " + str);
1090    return executeUpdate(sql,_Connection.COLUMNNAMES,columnNames);
1091  }
1092
1093  /**
1094   * Executes the given SQL statement, which may return multiple results,
1095   * and signals the driver that any
1096   * auto-generated keys should be made available
1097   * for retrieval. The driver will ignore this signal if the SQL statement
1098   * is not an <code>INSERT</code> statement.
1099   * <P>
1100   * In some (uncommon) situations, a single SQL statement may return
1101   * multiple result sets and/or update counts. Normally you can ignore
1102   * this unless you are (1) executing a stored procedure that you know may
1103   * return multiple results or (2) you are dynamically executing an
1104   * unknown SQL string.
1105   * <P>
1106       * The <code>execute</code> method executes an SQL statement and indicates the
1107   * form of the first result. You must then use the methods
1108   * <code>getResultSet</code> or <code>getUpdateCount</code>
1109   * to retrieve the result, and <code>getMoreResults</code> to
1110   * move to any subsequent result(s).
1111   *
1112   * @param sql any SQL statement
1113   * @param autoGeneratedKeys a constant indicating whether auto-generated
1114   * keys should be made available for retrieval using the method
1115   * <code>getGeneratedKeys</code>; one of the following constants:
1116   * <code>Statement.RETURN_GENERATED_KEYS</code> or
1117   * <code>Statement.NO_GENERATED_KEYS</code>
1118   * @return <code>true</code> if the first result is a <code>ResultSet</code>
1119   * object; <code>false</code> if it is an update count or there are
1120   * no results
1121   * @exception SQLException if a database access error occurs
1122   * @see #getResultSet
1123   * @see #getUpdateCount
1124   * @see #getMoreResults
1125   * @see #getGeneratedKeys
1126   *
1127   * @since 1.4
1128   */

1129
1130  /** @todo Work to be done */
1131  public synchronized boolean execute(String JavaDoc sql, int autoGeneratedKeys) throws SQLException {
1132    if(autoGeneratedKeys == NO_GENERATED_KEYS)
1133      return execute(sql);
1134    checkConnection();
1135    writeToLog(sql + ", " + autoGeneratedKeys);
1136    return execute(sql,_Connection.AUTOGENERATEDKEYS,null);
1137  }
1138
1139
1140  /**
1141   * Executes the given SQL statement, which may return multiple results,
1142   * and signals the driver that the
1143   * auto-generated keys indicated in the given array should be made available
1144   * for retrieval. This array contains the indexes of the columns in the
1145   * target table that contain the auto-generated keys that should be made
1146   * available. The driver will ignore the array if the given SQL statement
1147   * is not an <code>INSERT</code> statement.
1148   * <P>
1149   * Under some (uncommon) situations, a single SQL statement may return
1150   * multiple result sets and/or update counts. Normally you can ignore
1151   * this unless you are (1) executing a stored procedure that you know may
1152   * return multiple results or (2) you are dynamically executing an
1153   * unknown SQL string.
1154   * <P>
1155   * The <code>execute</code> method executes an SQL statement and indicates the
1156   * form of the first result. You must then use the methods
1157   * <code>getResultSet</code> or <code>getUpdateCount</code>
1158   * to retrieve the result, and <code>getMoreResults</code> to
1159   * move to any subsequent result(s).
1160   *
1161   * @param sql any SQL statement
1162   * @param columnIndexes an array of the indexes of the columns in the
1163   * inserted row that should be made available for retrieval by a
1164   * call to the method <code>getGeneratedKeys</code>
1165   * @return <code>true</code> if the first result is a <code>ResultSet</code>
1166   * object; <code>false</code> if it is an update count or there
1167   * are no results
1168   * @exception SQLException if a database access error occurs
1169   * @see #getResultSet
1170   * @see #getUpdateCount
1171   * @see #getMoreResults
1172   *
1173   * @since 1.4
1174   */

1175
1176  /** @todo Work to be done */
1177  public synchronized boolean execute(String JavaDoc sql, int columnIndexes[]) throws SQLException {
1178    checkConnection();
1179    if(columnIndexes == null){
1180      addWarning("NO Generated Keys will be retrived as, NO ColumnIndexes were passed");
1181      return execute(sql);
1182    }
1183    int length = columnIndexes.length;
1184    String JavaDoc str = " [";
1185    for (int i = 0; i < length; i++)
1186      str += (columnIndexes[i] + " ");
1187    writeToLog(sql + ", " + str);
1188    return execute(sql,_Connection.COLUMNINDEXES,columnIndexes);
1189  }
1190
1191  /**
1192   * Executes the given SQL statement, which may return multiple results,
1193   * and signals the driver that the
1194   * auto-generated keys indicated in the given array should be made available
1195   * for retrieval. This array contains the names of the columns in the
1196   * target table that contain the auto-generated keys that should be made
1197   * available. The driver will ignore the array if the given SQL statement
1198   * is not an <code>INSERT</code> statement.
1199   * <P>
1200   * In some (uncommon) situations, a single SQL statement may return
1201   * multiple result sets and/or update counts. Normally you can ignore
1202   * this unless you are (1) executing a stored procedure that you know may
1203   * return multiple results or (2) you are dynamically executing an
1204   * unknown SQL string.
1205   * <P>
1206       * The <code>execute</code> method executes an SQL statement and indicates the
1207   * form of the first result. You must then use the methods
1208   * <code>getResultSet</code> or <code>getUpdateCount</code>
1209   * to retrieve the result, and <code>getMoreResults</code> to
1210   * move to any subsequent result(s).
1211   *
1212   * @param sql any SQL statement
1213   * @param columnNames an array of the names of the columns in the inserted
1214   * row that should be made available for retrieval by a call to the
1215   * method <code>getGeneratedKeys</code>
1216   * @return <code>true</code> if the next result is a <code>ResultSet</code>
1217   * object; <code>false</code> if it is an update count or there
1218   * are no more results
1219   * @exception SQLException if a database access error occurs
1220   * @see #getResultSet
1221   * @see #getUpdateCount
1222   * @see #getMoreResults
1223   * @see #getGeneratedKeys
1224   *
1225   * @since 1.4
1226   */

1227
1228  /** @todo Work to be done */
1229  public synchronized boolean execute(String JavaDoc sql, String JavaDoc columnNames[]) throws SQLException {
1230    checkConnection();
1231    if(columnNames == null){
1232      addWarning("NO Generated Keys will be retrived as, NO ColumnNames were passed");
1233      return execute(sql);
1234    }
1235    int length = columnNames.length;
1236    String JavaDoc str = " [";
1237    for (int i = 0; i < length; i++)
1238      str += (columnNames[i] + " ");
1239    writeToLog(sql + ", " + str);
1240    return execute(sql,_Connection.COLUMNNAMES,columnNames);
1241  }
1242
1243  /**
1244   * Retrieves the result set holdability for <code>ResultSet</code> objects
1245   * generated by this <code>Statement</code> object.
1246   *
1247   * @return either <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
1248   * <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
1249   * @exception SQLException if a database access error occurs
1250   *
1251   * @since 1.4
1252   */

1253
1254  public synchronized int getResultSetHoldability() throws SQLException {
1255    checkConnection();
1256    DException dex = new DException("DSE16",
1257                                    new Object JavaDoc[] {"getResultSetHoldability"});
1258    throw dex.getSqlException(locale);
1259  }
1260
1261      /*-------------------- Methods Common to all Statements ----------------------*/
1262
1263  /**
1264   * @ todo
1265   * What is this ??????????
1266   * This connection can never be null
1267   * Check connection.isClosed() instead
1268   */

1269
1270  protected void checkConnection() throws SQLException {
1271    if (connection == null ) {
1272      DException dex = new DException("DSE940", null);
1273      throw dex.getSqlException(locale);
1274    }
1275    if (connection.isClosed()) {
1276      DException dex = new DException("DSE279", null);
1277      throw dex.getSqlException(locale);
1278    }
1279  }
1280
1281  protected void createEnvironmentToExecute(boolean clearBatch) throws
1282      SQLException {
1283    clearWarnings();
1284    dmlResult = null;
1285    if (clearBatch) {
1286      if (batchList != null && batchList.size() > 0) {
1287        addWarning("Clearing batchList for createEnvironmentToExecute");
1288        batchList.clear();
1289      }
1290    }
1291  }
1292
1293  protected void setRecordSetBufferAttributes(_RecordSetBuffer rsb) {
1294    rsb.setMaxRows(maxRows);
1295    rsb.setMaxFieldSize(maxFieldSize);
1296  }
1297
1298  protected void setResultSetAttributes() throws SQLException {
1299    resultSet.setFetchDirection(fetchDirection);
1300    resultSet.setFetchSize(fetchSize);
1301    resultSet.setType(resultSetType);
1302    resultSet.setConcurreny(resultSetConcurrency);
1303  }
1304
1305  protected void addWarning(String JavaDoc warning) throws SQLException {
1306    if (sqlWarnings == null) {
1307      sqlWarnings = new SQLWarning(warning);
1308      return;
1309    }
1310    sqlWarnings.setNextWarning(new SQLWarning(warning));
1311  }
1312
1313  protected void printRSB(_RecordSetBuffer rsb) throws SQLException {
1314    try {
1315      _RecordSetBufferIterator rsbi = rsb.getIterator();
1316      if (rsbi.top()) {
1317        int count = rsb.getColumnCharacteristics().getColumnCount();
1318        do {
1319          _Record r = rsbi.getRecord();
1320          for (int j = 0; j < count; j++) {
1321            System.out.print(r.getColumnValue(j + 1) + "\t");
1322          }
1323        }
1324        while (rsbi.next());
1325
1326      }
1327      else
1328         ;//// Removed By Program ** System.out.println("********* no data in resultset ********* ");
1329

1330    }
1331    catch (DException ex) {
1332      throw ex.getSqlException(connection.locale);
1333    }
1334  }
1335
1336  protected String JavaDoc changeQueryForDB(String JavaDoc query) throws SQLException {
1337    query = changeForDropQuery(query);
1338    return escapeProcessingEnabled ? connection.nativeSQL(query) : query;
1339  }
1340
1341  public String JavaDoc changeForDropQuery(String JavaDoc query) throws SQLException {
1342    query = query.trim();
1343    String JavaDoc toRepleace = "long bit varying";
1344    int ndx = query.toLowerCase().indexOf(toRepleace);
1345    StringBuffer JavaDoc sb = new StringBuffer JavaDoc(query);
1346    if (ndx > -1)
1347      sb.replace(ndx, ndx + toRepleace.length(), "LONG VARBINARY");
1348    query = sb.toString();
1349    return query;
1350  }
1351
1352  protected static Object JavaDoc[] getRequiredObjectOfexecute(Object JavaDoc returnObject,
1353                                                  int concurrency,int maxrows) throws
1354      DException, SQLException {
1355    if (returnObject instanceof _SelectIterator)
1356      return getRequiredObjectOfexecuteQuery(returnObject, concurrency,maxrows) ;
1357    return new Object JavaDoc[] {returnObject,new Integer JavaDoc (concurrency)};
1358  }
1359
1360  private static Object JavaDoc[] getRequiredObjectOfexecuteQuery(Object JavaDoc returnObject,
1361      int concurrency,int maxRows) throws DException, SQLException {
1362    _SelectIterator retriever = (_SelectIterator) returnObject;
1363    if (concurrency == ResultSet.CONCUR_UPDATABLE && retriever.isUpdatable()) {
1364      RecordSetUpdateable rsb = new RecordSetUpdateable();
1365      rsb.setSelectIterator(retriever);
1366      return new Object JavaDoc[]{rsb,new Integer JavaDoc(ResultSet.CONCUR_UPDATABLE)};
1367    }
1368    RecordSet rsb = new RecordSet();
1369    rsb.setSelectIterator(retriever);
1370    return new Object JavaDoc[]{rsb,new Integer JavaDoc(ResultSet.CONCUR_READ_ONLY)};
1371  }
1372
1373  protected synchronized int executeUpdate(String JavaDoc query, boolean clearBatch) throws
1374      SQLException {
1375    checkConnection();
1376    if (query == null || query.length() == 0) {
1377      DException dex = new DException("DSE828", null);
1378      throw dex.getSqlException(locale);
1379    }
1380    writeToLog("Update" , query);
1381    createEnvironmentToExecute(clearBatch);
1382    if (resultSet != null) {
1383      resultSet.close();
1384      resultSet = null;
1385    }
1386    updateCount = -1;
1387
1388    String JavaDoc queryForDB = changeQueryForDB(query);
1389    Object JavaDoc result = null;
1390    try {
1391   synchronized (connection) {
1392        result = connection.getServerConnection().executeUpdate(queryForDB,
1393            queryTimeOut);
1394
1395      }
1396 }
1397    catch (DException dex) {
1398      throw dex.getSqlException(locale);
1399    }
1400    updateCount = result.hashCode();
1401    updateCount = updateCount == Integer.MIN_VALUE ? 0 : updateCount;
1402    return updateCount;
1403  }
1404
1405  private boolean execute(String JavaDoc query ,int paramType,Object JavaDoc param) throws SQLException{
1406    if (query == null || query.length() == 0) {
1407      DException dex = new DException("DSE828", null);
1408      throw dex.getSqlException(locale);
1409    }
1410    createEnvironmentToExecute(true);
1411    if (resultSet != null) {
1412      resultSet.close();
1413      resultSet = null;
1414    }
1415    currentResultIndex = 0;
1416    updateCount = -1;
1417
1418    String JavaDoc queryForDB = changeQueryForDB(query);
1419    Object JavaDoc[] reqObject = null;
1420    try {
1421      synchronized (connection) {
1422        executeResult = new Object JavaDoc[] { connection.getServerConnection().execute(queryForDB, queryTimeOut, resultSetConcurrency == ResultSet.CONCUR_UPDATABLE ?
1423                                            IteratorConstants.UPDATABLE :
1424                                            IteratorConstants.NONSCROLLABLE,_Connection.EXECUTE,
1425                                            paramType,param)};
1426      }
1427     reqObject = getRequiredObjectOfexecute(executeResult[0],
1428          resultSetConcurrency,maxRows);
1429    }
1430    catch (DException dex) {
1431      throw dex.getSqlException(connection.getLocale());
1432    }
1433
1434    if (reqObject[0] instanceof _RecordSetBuffer) {
1435      executeResult[0] = reqObject[0];
1436      _RecordSetBuffer rsb = (_RecordSetBuffer) reqObject[0];
1437      resultSet = new DaffodilDBResultSet(this);
1438      resultSet.setRecordSetBuffer(rsb);
1439      int oldResultSetCon = resultSetConcurrency;
1440      resultSetConcurrency = reqObject[1].hashCode();
1441      if(oldResultSetCon != resultSetConcurrency )
1442        addWarning("the resultSet Concurency is set ResultSet.CONCUR_READ_ONLY " ) ;
1443      setResultSetAttributes();
1444      setRecordSetBufferAttributes(rsb);
1445      resultSetConcurrency = oldResultSetCon;
1446      return true;
1447    }
1448    if(reqObject[0] instanceof DMLResult){
1449      dmlResult = (DMLResult)reqObject[0];
1450      executeResult[0] = new Integer JavaDoc(dmlResult.rowsEffected);
1451    }else{
1452      executeResult[0] = reqObject[0];
1453    }
1454    updateCount = executeResult[0].hashCode();
1455    updateCount = updateCount == Integer.MIN_VALUE ? 0 : updateCount;
1456    return false;
1457  }
1458
1459  private int executeUpdate(String JavaDoc query,int paramType ,Object JavaDoc parm) throws
1460      SQLException {
1461    checkConnection();
1462    if (query == null || query.length() == 0) {
1463      DException dex = new DException("DSE828", null);
1464      throw dex.getSqlException(locale);
1465    }
1466    createEnvironmentToExecute(true);
1467    if (resultSet != null) {
1468      resultSet.close();
1469      resultSet = null;
1470    }
1471    updateCount = -1;
1472
1473    String JavaDoc queryForDB = changeQueryForDB(query);
1474    Object JavaDoc result = null;
1475    try {
1476      synchronized (connection) {
1477        result = connection.getServerConnection().execute(queryForDB,
1478            queryTimeOut, IteratorConstants.NONSCROLLABLE, _Connection.EXECUTEUPDATE, paramType, parm);
1479      }
1480      if (result instanceof DMLResult) {
1481        dmlResult = (DMLResult) result;
1482        updateCount = dmlResult.rowsEffected;
1483      }
1484      else {
1485        updateCount = result.hashCode();
1486        updateCount = updateCount == Integer.MIN_VALUE ? 0 : updateCount;
1487      }
1488    }
1489    catch (DException dex) {
1490      throw dex.getSqlException(locale);
1491    }
1492    return updateCount;
1493  }
1494
1495
1496}
1497
Popular Tags