KickJava   Java API By Example, From Geeks To Geeks.

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


1 package in.co.daffodil.db.jdbc;
2
3 import java.math.*;
4 import java.sql.*;
5 import java.sql.Date JavaDoc;
6 import java.util.*;
7 import com.daffodilwoods.daffodildb.client.*;
8 import com.daffodilwoods.daffodildb.server.serversystem.*;
9 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
10 import com.daffodilwoods.database.resource.*;
11 import in.co.daffodil.db.general.*;
12 import com.daffodilwoods.daffodildb.server.sql99.dql.listenerevents.*;
13
14 /**
15  * The interface used to execute SQL stored procedures. The JDBC API
16  * provides a stored procedure SQL escape syntax that allows stored procedures
17  * to be called in a standard way for all RDBMSs. This escape syntax has one
18  * form that includes a result parameter and one that does not. If used, the result
19  * parameter must be registered as an OUT parameter. The other parameters
20  * can be used for input, output or both. Parameters are referred to
21  * sequentially, by number, with the first parameter being 1.
22  * <PRE>
23  * {?= call &lt;procedure-name&gt;[&lt;arg1&gt;,&lt;arg2&gt;, ...]}
24  * {call &lt;procedure-name&gt;[&lt;arg1&gt;,&lt;arg2&gt;, ...]}
25  * </PRE>
26  * <P>
27      * IN parameter values are set using the <code>set</code> methods inherited from
28  * {@link PreparedStatement}. The type of all OUT parameters must be
29  * registered prior to executing the stored procedure; their values
30      * are retrieved after execution via the <code>get</code> methods provided here.
31  * <P>
32  * A <code>CallableStatement</code> can return one {@link ResultSet} object or
33  * multiple <code>ResultSet</code> objects. Multiple
34  * <code>ResultSet</code> objects are handled using operations
35  * inherited from {@link Statement}.
36  * <P>
37  * For maximum portability, a call's <code>ResultSet</code> objects and
38  * update counts should be processed prior to getting the values of output
39  * parameters.
40  * <P>
41  *
42  * @see Connection#prepareCall
43  * @see ResultSet
44  * <br><br>
45  * <B>Last Updated </B>
46  * <U> Dec. 20,2004 </U><br>
47  * <I>Purpose :To provide method synchronization . </I><br>
48  * <B>Author</B> Manoj Kr. Sheoran<br>
49
50  */

51 public class DaffodilDBCallableStatement
52     extends DaffodilDBPreparedStatement
53     implements CallableStatement {
54
55   /**
56    * contains parameter name to parameter value mapping
57    */

58   private HashMap parameterMap;
59
60   /**
61    * contains output parameter to their registered data type mapping
62    */

63   private HashMap outParametersTypeMap;
64
65   /**
66    * contains value of out parameter after execution of callable statement
67    * in this case out parameters are accesible only through indexes
68    */

69   private Object JavaDoc[] outParameter;
70
71   /**
72    * contains value of out parameter after execution of callable statement
73    * in this case out parameters are accesible onlu through parameter name
74    * out paramter name value to ou parameter value mapping
75    */

76   private HashMap outParameterMap;
77
78   /**
79    * All Parameters after execution be it out/in
80    */

81     private Object JavaDoc outParameters;
82
83
84
85   private Object JavaDoc lastOutParameterRetrieved;
86   private int outParametersCount;
87
88   boolean flagIndexParameterUsed = false;
89   boolean flagNamedParameterUsed = false;
90
91   public DaffodilDBCallableStatement(DaffodilDBConnection connection,
92                                      String JavaDoc query) throws SQLException {
93     this(connection, query, ResultSet.TYPE_FORWARD_ONLY,
94          ResultSet.CONCUR_READ_ONLY);
95   }
96
97   public DaffodilDBCallableStatement(DaffodilDBConnection connection,
98                                      String JavaDoc query, int resultSetType,
99                                      int resultSetConcurrency) throws
100       SQLException {
101     this(connection, query, ResultSet.TYPE_FORWARD_ONLY,
102          ResultSet.CONCUR_READ_ONLY,
103          1 /*ResultSet.HOLD_CURSORS_OVER_COMMIT*/);
104   }
105
106   public DaffodilDBCallableStatement(DaffodilDBConnection connection,
107                                      String JavaDoc query, int resultSetType,
108                                      int resultSetConcurrency,
109                                      int resultSetHoldability) throws
110       SQLException {
111     super(connection, query, resultSetType, resultSetConcurrency,
112           resultSetHoldability);
113     outParametersCount = 0;
114   }
115
116   /**
117    * Registers the OUT parameter in ordinal position
118    * <code>parameterIndex</code> to the JDBC type
119    * <code>sqlType</code>. All OUT parameters must be registered
120    * before a stored procedure is executed.
121    * <p>
122    * The JDBC type specified by <code>sqlType</code> for an OUT
123    * parameter determines the Java type that must be used
124    * in the <code>get</code> method to read the value of that parameter.
125    * <p>
126    * If the JDBC type expected to be returned to this output parameter
127    * is specific to this particular database, <code>sqlType</code>
128    * should be <code>java.sql.Types.OTHER</code>. The method
129    * {@link #getObject} retrieves the value.
130    *
131    * @param parameterIndex the first parameter is 1, the second is 2,
132    * and so on
133    * @param sqlType the JDBC type code defined by <code>java.sql.Types</code>.
134    * If the parameter is of JDBC type <code>NUMERIC</code>
135    * or <code>DECIMAL</code>, the version of
136    * <code>registerOutParameter</code> that accepts a scale value
137    * should be used.
138    *
139    * @exception SQLException if a database access error occurs
140    * @see Types
141    */

142
143   public synchronized void registerOutParameter(int parameterIndex, int sqlType) throws
144       SQLException {
145     registerOutParameter(parameterIndex, new SQLType(sqlType));
146   }
147
148   /**
149    * Registers the parameter in ordinal position
150    * <code>parameterIndex</code> to be of JDBC type
151    * <code>sqlType</code>. This method must be called
152    * before a stored procedure is executed.
153    * <p>
154    * The JDBC type specified by <code>sqlType</code> for an OUT
155    * parameter determines the Java type that must be used
156    * in the <code>get</code> method to read the value of that parameter.
157    * <p>
158    * This version of <code>registerOutParameter</code> should be
159    * used when the parameter is of JDBC type <code>NUMERIC</code>
160    * or <code>DECIMAL</code>.
161    *
162    * @param parameterIndex the first parameter is 1, the second is 2,
163    * and so on
164    * @param sqlType the SQL type code defined by <code>java.sql.Types</code>.
165    * @param scale the desired number of digits to the right of the
166    * decimal point. It must be greater than or equal to zero.
167    * @exception SQLException if a database access error occurs
168    * @see Types
169    */

170
171   public synchronized void registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException {
172     registerOutParameter(parameterIndex, new SQLType(sqlType, scale));
173   }
174
175   /**
176    * Retrieves whether the last OUT parameter read had the value of
177    * SQL <code>NULL</code>. Note that this method should be called only after
178    * calling a getter method; otherwise, there is no value to use in
179    * determining whether it is <code>null</code> or not.
180    *
181    * @return <code>true</code> if the last parameter read was SQL
182    * <code>NULL</code>; <code>false</code> otherwise
183    * @exception SQLException if a database access error occurs
184    *
185    * @ todo wasNull
186    * Check if correct
187    */

188   public synchronized boolean wasNull() throws SQLException {
189     return lastOutParameterRetrieved == null;
190   }
191
192   /**
193    * Retrieves the value of the designated JDBC <code>CHAR</code>,
194    * <code>VARCHAR</code>, or <code>LONGVARCHAR</code> parameter as a
195    * <code>String</code> in the Java programming language.
196    * <p>
197    * For the fixed-length type JDBC <code>CHAR</code>,
198    * the <code>String</code> object
199    * returned has exactly the same value the JDBC
200    * <code>CHAR</code> value had in the
201    * database, including any padding added by the database.
202    *
203    * @param parameterIndex the first parameter is 1, the second is 2,
204    * and so on
205    * @return the parameter value. If the value is SQL <code>NULL</code>,
206    * the result
207    * is <code>null</code>.
208    * @exception SQLException if a database access error occurs
209    * @see #setString
210    *
211    */

212
213   public synchronized String JavaDoc getString(int parameterIndex) throws SQLException {
214     isValidOUTParameterIndex(parameterIndex);
215     checkTypeEqual(parameterIndex, "String");
216     return outParameter[parameterIndex - 1] == null ? null :
217         outParameter[parameterIndex - 1].toString();
218   }
219
220   /**
221    * Retrieves the value of the designated JDBC <code>BIT</code> parameter as a
222    * <code>boolean</code> in the Java programming language.
223    *
224    * @param parameterIndex the first parameter is 1, the second is 2,
225    * and so on
226    * @return the parameter value. If the value is SQL <code>NULL</code>,
227    * the result is <code>false</code>.
228    * @exception SQLException if a database access error occurs
229    * @see #setBoolean
230    */

231
232   public synchronized boolean getBoolean(int parameterIndex) throws SQLException {
233     isValidOUTParameterIndex(parameterIndex);
234     checkTypeEqual(parameterIndex, Types.BIT, -1);
235     try {
236       Boolean JavaDoc bool = (Boolean JavaDoc) Utilities.convertObject(outParameter[
237           parameterIndex - 1], Types.BIT);
238       return bool == null ? false : bool.booleanValue();
239     }
240     catch (DException dxe) {
241       throw dxe.getSqlException(connection.getLocale());
242     }
243   }
244
245   /**
246    * Retrieves the value of the designated JDBC <code>TINYINT</code> parameter
247    * as a <code>byte</code> in the Java programming language.
248    *
249    * @param parameterIndex the first parameter is 1, the second is 2,
250    * and so on
251    * @return the parameter value. If the value is SQL <code>NULL</code>, the result
252    * is <code>0</code>.
253    * @exception SQLException if a database access error occurs
254    * @see #setByte
255    */

256
257   public synchronized byte getByte(int parameterIndex) throws SQLException {
258     isValidOUTParameterIndex(parameterIndex);
259     checkTypeEqual(parameterIndex, Types.TINYINT, -1);
260     try {
261       Integer JavaDoc bool = (Integer JavaDoc) Utilities.convertObject(outParameter[
262           parameterIndex - 1], Types.TINYINT);
263       return bool == null ? 0 : bool.byteValue();
264     }
265     catch (DException dxe) {
266       throw dxe.getSqlException(connection.getLocale());
267     }
268   }
269
270   /**
271    * Retrieves the value of the designated JDBC <code>SMALLINT</code> parameter
272    * as a <code>short</code> in the Java programming language.
273    *
274    * @param parameterIndex the first parameter is 1, the second is 2,
275    * and so on
276    * @return the parameter value. If the value is SQL <code>NULL</code>, the result
277    * is <code>0</code>.
278    * @exception SQLException if a database access error occurs
279    * @see #setShort
280    */

281
282   public synchronized short getShort(int parameterIndex) throws SQLException {
283     isValidOUTParameterIndex(parameterIndex);
284     checkTypeEqual(parameterIndex, Types.SMALLINT, -1);
285     try {
286       Integer JavaDoc bool = (Integer JavaDoc) Utilities.convertObject(outParameter[
287           parameterIndex - 1], Types.SMALLINT);
288       return bool == null ? 0 : bool.shortValue();
289     }
290     catch (DException dxe) {
291       throw dxe.getSqlException(connection.getLocale());
292     }
293   }
294
295   /**
296    * Retrieves the value of the designated JDBC <code>INTEGER</code> parameter
297    * as an <code>int</code> in the Java programming language.
298    *
299    * @param parameterIndex the first parameter is 1, the second is 2,
300    * and so on
301    * @return the parameter value. If the value is SQL <code>NULL</code>, the result
302    * is <code>0</code>.
303    * @exception SQLException if a database access error occurs
304    * @see #setInt
305    */

306
307   public synchronized int getInt(int parameterIndex) throws SQLException {
308     isValidOUTParameterIndex(parameterIndex);
309     checkTypeEqual(parameterIndex, Types.INTEGER, -1);
310     try {
311       Integer JavaDoc bool = (Integer JavaDoc) Utilities.convertObject(outParameter[
312           parameterIndex - 1], Types.INTEGER);
313       return bool == null ? 0 : bool.intValue();
314     }
315     catch (DException dxe) {
316       throw dxe.getSqlException(connection.getLocale());
317     }
318   }
319
320   /**
321    * Retrieves the value of the designated JDBC <code>BIGINT</code> parameter
322    * as a <code>long</code> in the Java programming language.
323    *
324    * @param parameterIndex the first parameter is 1, the second is 2,
325    * and so on
326    * @return the parameter value. If the value is SQL <code>NULL</code>, the result
327    * is <code>0</code>.
328    * @exception SQLException if a database access error occurs
329    * @see #setLong
330    */

331   public synchronized long getLong(int parameterIndex) throws SQLException {
332     isValidOUTParameterIndex(parameterIndex);
333     checkTypeEqual(parameterIndex, Types.BIGINT, -1);
334     try {
335       Long JavaDoc bool = (Long JavaDoc) Utilities.convertObject(outParameter[parameterIndex -
336                                                  1], Types.BIGINT);
337       return bool == null ? 0 : bool.longValue();
338     }
339     catch (DException dxe) {
340       throw dxe.getSqlException(connection.getLocale());
341     }
342   }
343
344   /**
345    * Retrieves the value of the designated JDBC <code>FLOAT</code> parameter
346    * as a <code>float</code> in the Java programming language.
347    *
348    * @param parameterIndex the first parameter is 1, the second is 2,
349    * and so on
350    * @return the parameter value. If the value is SQL <code>NULL</code>, the result
351    * is <code>0</code>.
352    * @exception SQLException if a database access error occurs
353    * @see #setFloat
354    */

355
356   public synchronized float getFloat(int parameterIndex) throws SQLException {
357     isValidOUTParameterIndex(parameterIndex);
358     checkTypeEqual(parameterIndex, Types.FLOAT, -1);
359     try {
360       Double JavaDoc value = (Double JavaDoc) Utilities.convertObject(outParameter[
361           parameterIndex - 1], Types.FLOAT);
362       return value == null ? 0 : value.floatValue();
363     }
364     catch (DException dxe) {
365       throw dxe.getSqlException(connection.getLocale());
366     }
367   }
368
369   /**
370    * Retrieves the value of the designated JDBC <code>DOUBLE</code> parameter as a <code>double</code>
371    * in the Java programming language.
372    * @param parameterIndex the first parameter is 1, the second is 2,
373    * and so on
374    * @return the parameter value. If the value is SQL <code>NULL</code>, the result
375    * is <code>0</code>.
376    * @exception SQLException if a database access error occurs
377    * @see #setDouble
378    */

379   public synchronized double getDouble(int parameterIndex) throws SQLException {
380     isValidOUTParameterIndex(parameterIndex);
381     checkTypeEqual(parameterIndex, Types.DOUBLE, -1);
382     try {
383       Double JavaDoc bool = (Double JavaDoc) Utilities.convertObject(outParameter[
384           parameterIndex - 1], Types.DOUBLE);
385       return bool == null ? 0 : bool.doubleValue();
386     }
387     catch (DException dxe) {
388       throw dxe.getSqlException(connection.getLocale());
389     }
390   }
391
392   /**
393    * Retrieves the value of the designated JDBC <code>NUMERIC</code> parameter as a
394    * <code>java.math.BigDecimal</code> object with <i>scale</i> digits to
395    * the right of the decimal point.
396    * @param parameterIndex the first parameter is 1, the second is 2,
397    * and so on
398    * @param scale the number of digits to the right of the decimal point
399    * @return the parameter value. If the value is SQL <code>NULL</code>, the result
400    * is <code>null</code>.
401    * @exception SQLException if a database access error occurs
402    * @deprecated use <code>getBigDecimal(int parameterIndex)</code>
403    * or <code>getBigDecimal(String parameterName)</code>
404    * @see #setBigDecimal
405    */

406   public synchronized BigDecimal getBigDecimal(int parameterIndex, int scale) throws
407       SQLException {
408     isValidOUTParameterIndex(parameterIndex);
409     SQLType sqlType = checkTypeEqual(parameterIndex, Types.DECIMAL, scale);
410     scale = sqlType.getScale();
411     try {
412       BigDecimal bd = (BigDecimal) Utilities.convertObject(outParameter[
413           parameterIndex - 1], Types.DECIMAL);
414       return (scale == -1 || bd==null) ? bd : bd.setScale(scale, bd.ROUND_DOWN);
415     }
416     catch (DException dxe) {
417       throw dxe.getSqlException(connection.getLocale());
418     }
419   }
420
421   /**
422    * Retrieves the value of the designated JDBC <code>BINARY</code> or
423    * <code>VARBINARY</code> parameter as an array of <code>byte</code>
424    * values in the Java programming language.
425    * @param parameterIndex the first parameter is 1, the second is 2,
426    * and so on
427    * @return the parameter value. If the value is SQL <code>NULL</code>, the result
428    * is <code>null</code>.
429    * @exception SQLException if a database access error occurs
430    * @see #setBytes
431    */

432
433   public synchronized byte[] getBytes(int parameterIndex) throws SQLException {
434     isValidOUTParameterIndex(parameterIndex);
435     checkTypeEqual(parameterIndex, "Binary");
436     try {
437       return (byte[]) Utilities.convertObject(outParameter[parameterIndex - 1],
438                                               Types.BINARY);
439     }
440     catch (DException dxe) {
441       throw dxe.getSqlException(connection.getLocale());
442     }
443   }
444
445   /**
446    * Retrieves the value of the designated JDBC <code>DATE</code> parameter as a
447    * <code>java.sql.Date</code> object.
448    * @param parameterIndex the first parameter is 1, the second is 2,
449    * and so on
450    * @return the parameter value. If the value is SQL <code>NULL</code>, the result
451    * is <code>null</code>.
452    * @exception SQLException if a database access error occurs
453    * @see #setDate
454    */

455
456   public synchronized java.sql.Date JavaDoc getDate(int parameterIndex) throws SQLException {
457     return getDate(parameterIndex, null);
458   }
459
460   /**
461    * Retrieves the value of the designated JDBC <code>TIME</code> parameter as a
462    * <code>java.sql.Time</code> object.
463    *
464    * @param parameterIndex the first parameter is 1, the second is 2,
465    * and so on
466    * @return the parameter value. If the value is SQL <code>NULL</code>, the result
467    * is <code>null</code>.
468    * @exception SQLException if a database access error occurs
469    * @see #setTime
470    */

471
472   public synchronized java.sql.Time JavaDoc getTime(int parameterIndex) throws SQLException {
473     return getTime(parameterIndex, null);
474   }
475
476   /**
477    * Retrieves the value of the designated JDBC <code>TIMESTAMP</code> parameter as a
478    * <code>java.sql.Timestamp</code> object.
479    *
480    * @param parameterIndex the first parameter is 1, the second is 2,
481    * and so on
482    * @return the parameter value. If the value is SQL <code>NULL</code>, the result
483    * is <code>null</code>.
484    * @exception SQLException if a database access error occurs
485    * @see #setTimestamp
486    */

487
488   public synchronized java.sql.Timestamp JavaDoc getTimestamp(int parameterIndex) throws
489       SQLException {
490     return getTimestamp(parameterIndex, null);
491   }
492
493
494   /**
495    * Retrieves the value of the designated parameter as an <code>Object</code>
496        * in the Java programming language. If the value is an SQL <code>NULL</code>,
497    * the driver returns a Java <code>null</code>.
498    * <p>
499    * This method returns a Java object whose type corresponds to the JDBC
500    * type that was registered for this parameter using the method
501    * <code>registerOutParameter</code>. By registering the target JDBC
502    * type as <code>java.sql.Types.OTHER</code>, this method can be used
503    * to read database-specific abstract data types.
504    *
505    * @param parameterIndex the first parameter is 1, the second is 2,
506    * and so on
507    * @return A <code>java.lang.Object</code> holding the OUT parameter value
508    * @exception SQLException if a database access error occurs
509    * @see Types
510    * @see #setObject
511    */

512
513   public synchronized Object JavaDoc getObject(int parameterIndex) throws SQLException {
514     return getObject(parameterIndex, null);
515   }
516
517
518   /**
519        * Retrieves the value of the designated JDBC <code>NUMERIC</code> parameter as a
520    * <code>java.math.BigDecimal</code> object with as many digits to the
521    * right of the decimal point as the value contains.
522    * @param parameterIndex the first parameter is 1, the second is 2,
523    * and so on
524    * @return the parameter value in full precision. If the value is
525    * SQL <code>NULL</code>, the result is <code>null</code>.
526    * @exception SQLException if a database access error occurs
527    * @see #setBigDecimal
528    * @since 1.2
529    */

530
531   public synchronized BigDecimal getBigDecimal(int parameterIndex) throws SQLException {
532      return getBigDecimal(parameterIndex,-1 );
533   }
534
535   /**
536    * Returns an object representing the value of OUT parameter
537    * <code>i</code> and uses <code>map</code> for the custom
538    * mapping of the parameter value.
539    * <p>
540    * This method returns a Java object whose type corresponds to the
541    * JDBC type that was registered for this parameter using the method
542    * <code>registerOutParameter</code>. By registering the target
543    * JDBC type as <code>java.sql.Types.OTHER</code>, this method can
544    * be used to read database-specific abstract data types.
545    * @param i the first parameter is 1, the second is 2, and so on
546    * @param map the mapping from SQL type names to Java classes
547    * @return a <code>java.lang.Object</code> holding the OUT parameter value
548    * @exception SQLException if a database access error occurs
549    * @see #setObject
550    * @since 1.2
551    */

552
553   public synchronized Object JavaDoc getObject(int parameterIndex, java.util.Map JavaDoc map) throws
554       SQLException {
555     isValidOUTParameterIndex(parameterIndex);
556     SQLType sqlType = checkTypeEqual(parameterIndex, Types.OTHER, -1);
557     /**@todo map*/
558     try {
559       return Utilities.convertObject(outParameter[parameterIndex - 1],
560                                      sqlType.getType() /*,map*/);
561     }
562     catch (DException dxe) {
563       throw dxe.getSqlException(connection.getLocale());
564     }
565   }
566
567   /**
568    * Retrieves the value of the designated JDBC <code>REF(&lt;structured-type&gt;)</code>
569    * parameter as a {@link Ref} object in the Java programming language.
570    * @param i the first parameter is 1, the second is 2,
571    * and so on
572    * @return the parameter value as a <code>Ref</code> object in the
573        * Java programming language. If the value was SQL <code>NULL</code>, the value
574    * <code>null</code> is returned.
575    * @exception SQLException if a database access error occurs
576    * @since 1.2
577    *
578    * Note: not supporting as UDTs not allowed
579    */

580
581   public synchronized Ref getRef(int parameterIndex) throws SQLException {
582     DException dex = new DException("DSE16", new Object JavaDoc[] {"getRef"});
583     throw dex.getSqlException(connection.getLocale());
584   }
585
586   /**
587        * Retrieves the value of the designated JDBC <code>BLOB</code> parameter as a
588    * {@link Blob} object in the Java programming language.
589    * @param i the first parameter is 1, the second is 2, and so on
590    * @return the parameter value as a <code>Blob</code> object in the
591        * Java programming language. If the value was SQL <code>NULL</code>, the value
592    * <code>null</code> is returned.
593    * @exception SQLException if a database access error occurs
594    * @since 1.2
595    */

596
597   public synchronized Blob getBlob(int parameterIndex) throws SQLException {
598     isValidOUTParameterIndex(parameterIndex);
599     checkTypeEqual(parameterIndex, Types.BLOB, -1);
600     try {
601       return (Blob) Utilities.convertObject(outParameter[parameterIndex - 1],
602                                             Types.BLOB);
603     }
604     catch (DException dxe) {
605       throw dxe.getSqlException(connection.getLocale());
606     }
607   }
608
609   /**
610        * Retrieves the value of the designated JDBC <code>CLOB</code> parameter as a
611    * <code>Clob</code> object in the Java programming language.
612    * @param i the first parameter is 1, the second is 2, and
613    * so on
614    * @return the parameter value as a <code>Clob</code> object in the
615    * Java programming language. If the value was SQL <code>NULL</code>, the
616    * value <code>null</code> is returned.
617    * @exception SQLException if a database access error occurs
618    * @since 1.2
619    */

620
621   public synchronized Clob getClob(int parameterIndex) throws SQLException {
622     isValidOUTParameterIndex(parameterIndex);
623     checkTypeEqual(parameterIndex, Types.CLOB, -1);
624     try {
625       return (Clob) Utilities.convertObject(outParameter[parameterIndex - 1],
626                                             Types.CLOB);
627     }
628     catch (DException dxe) {
629       throw dxe.getSqlException(connection.getLocale());
630     }
631   }
632
633   /**
634    *
635        * Retrieves the value of the designated JDBC <code>ARRAY</code> parameter as an
636    * {@link Array} object in the Java programming language.
637    * @param i the first parameter is 1, the second is 2, and
638    * so on
639    * @return the parameter value as an <code>Array</code> object in
640        * the Java programming language. If the value was SQL <code>NULL</code>, the
641    * value <code>null</code> is returned.
642    * @exception SQLException if a database access error occurs
643    * @since 1.2
644    */

645
646   public synchronized Array getArray(int parameterIndex) throws SQLException {
647     DException dex = new DException("DSE22", new Object JavaDoc[] {"User-defined type"});
648     throw dex.getSqlException(connection.getLocale());
649   }
650
651   /**
652        * Retrieves the value of the designated JDBC <code>DATE</code> parameter as a
653    * <code>java.sql.Date</code> object, using
654    * the given <code>Calendar</code> object
655    * to construct the date.
656    * With a <code>Calendar</code> object, the driver
657    * can calculate the date taking into account a custom timezone and locale.
658    * If no <code>Calendar</code> object is specified, the driver uses the
659    * default timezone and locale.
660    *
661    * @param parameterIndex the first parameter is 1, the second is 2,
662    * and so on
663    * @param cal the <code>Calendar</code> object the driver will use
664    * to construct the date
665    * @return the parameter value. If the value is SQL <code>NULL</code>, the result
666    * is <code>null</code>.
667    * @exception SQLException if a database access error occurs
668    * @see #setDate
669    * @since 1.2
670    */

671
672   public synchronized java.sql.Date JavaDoc getDate(int parameterIndex, Calendar cal) throws
673       SQLException {
674     isValidOUTParameterIndex(parameterIndex);
675     checkTypeEqual(parameterIndex, Types.DATE, -1);
676     try {
677       java.sql.Date JavaDoc date = (Date JavaDoc) Utilities.convertObject(outParameter[
678           parameterIndex - 1], Types.DATE);
679       if (date == null || cal == null)
680         return date;
681       cal.setTime(date);
682       return new com.daffodilwoods.daffodildb.utils.DBDate(cal.getTime().getTime()
683           /*cal.get(Calendar.YEAR),cal.get(Calendar.MONTH),cal.get(Calendar.DATE)*/);
684     }
685     catch (DException dxe) {
686       throw dxe.getSqlException(connection.getLocale());
687     }
688   }
689
690   /**
691        * Retrieves the value of the designated JDBC <code>TIME</code> parameter as a
692    * <code>java.sql.Time</code> object, using
693    * the given <code>Calendar</code> object
694    * to construct the time.
695    * With a <code>Calendar</code> object, the driver
696    * can calculate the time taking into account a custom timezone and locale.
697    * If no <code>Calendar</code> object is specified, the driver uses the
698    * default timezone and locale.
699    *
700    * @param parameterIndex the first parameter is 1, the second is 2,
701    * and so on
702    * @param cal the <code>Calendar</code> object the driver will use
703    * to construct the time
704        * @return the parameter value; if the value is SQL <code>NULL</code>, the result
705    * is <code>null</code>.
706    * @exception SQLException if a database access error occurs
707    * @see #setTime
708    * @since 1.2
709    */

710
711   public synchronized java.sql.Time JavaDoc getTime(int parameterIndex, Calendar cal) throws
712       SQLException {
713     try {
714       isValidOUTParameterIndex(parameterIndex);
715       checkTypeEqual(parameterIndex, Types.TIME, -1);
716       Time tmObj = (Time) Utilities.convertObject(outParameter[parameterIndex -
717                                                   1], Types.TIME);
718       if (tmObj == null)
719         return null;
720       Date JavaDoc timeObject = new com.daffodilwoods.daffodildb.utils.DBDate(tmObj.getTime());
721       if (cal == null) {
722         Time time = new Time(timeObject.getTime());
723         return time;
724       }
725       cal.setTime(timeObject);
726       Time calTime = new Time(cal.getTime().getTime()
727           /*cal.get(Calendar.HOUR),cal.get(Calendar.MINUTE),
728                                        cal.get(Calendar.SECOND) */
);
729       return calTime;
730     }
731     catch (Exception JavaDoc e) {
732       DaffodilDBExceptionHandler.handle("error in getTime ", "", e,
733                                         connection.getLocale());
734     }
735     return null;
736   }
737
738   /**
739    * Retrieves the value of the designated JDBC <code>TIMESTAMP</code> parameter as a
740    * <code>java.sql.Timestamp</code> object, using
741    * the given <code>Calendar</code> object to construct
742    * the <code>Timestamp</code> object.
743    * With a <code>Calendar</code> object, the driver
744        * can calculate the timestamp taking into account a custom timezone and locale.
745    * If no <code>Calendar</code> object is specified, the driver uses the
746    * default timezone and locale.
747    *
748    *
749    * @param parameterIndex the first parameter is 1, the second is 2,
750    * and so on
751    * @param cal the <code>Calendar</code> object the driver will use
752    * to construct the timestamp
753    * @return the parameter value. If the value is SQL <code>NULL</code>, the result
754    * is <code>null</code>.
755    * @exception SQLException if a database access error occurs
756    * @see #setTimestamp
757    * @since 1.2
758    */

759
760   public synchronized java.sql.Timestamp JavaDoc getTimestamp(int parameterIndex, Calendar cal) throws
761       SQLException {
762     try {
763       isValidOUTParameterIndex(parameterIndex);
764       checkTypeEqual(parameterIndex, Types.TIME, -1);
765       Timestamp tmObj = (Timestamp) Utilities.convertObject(outParameter[
766           parameterIndex - 1], Types.TIMESTAMP);
767       if (tmObj == null)
768         return null;
769       Date JavaDoc timeObject = new com.daffodilwoods.daffodildb.utils.DBDate(tmObj.getTime());
770       if (cal == null) {
771         Timestamp time = new Timestamp(timeObject.getTime());
772         return time;
773       }
774       cal.setTime(timeObject);
775       Timestamp calTime = new Timestamp(cal.getTime().getTime());
776       return calTime;
777     }
778     catch (Exception JavaDoc e) {
779       DaffodilDBExceptionHandler.handle("error in getPropertyInfo", "", e,
780                                         connection.getLocale());
781       return null;
782     }
783   }
784
785   /**
786    * Registers the designated output parameter. This version of
787    * the method <code>registerOutParameter</code>
788    * should be used for a user-defined or <code>REF</code> output parameter. Examples
789    * of user-defined types include: <code>STRUCT</code>, <code>DISTINCT</code>,
790    * <code>JAVA_OBJECT</code>, and named array types.
791    *
792    * Before executing a stored procedure call, you must explicitly
793    * call <code>registerOutParameter</code> to register the type from
794    * <code>java.sql.Types</code> for each
795    * OUT parameter. For a user-defined parameter, the fully-qualified SQL
796    * type name of the parameter should also be given, while a <code>REF</code>
797    * parameter requires that the fully-qualified type name of the
798    * referenced type be given. A JDBC driver that does not need the
799    * type code and type name information may ignore it. To be portable,
800    * however, applications should always provide these values for
801    * user-defined and <code>REF</code> parameters.
802    *
803    * Although it is intended for user-defined and <code>REF</code> parameters,
804    * this method may be used to register a parameter of any JDBC type.
805        * If the parameter does not have a user-defined or <code>REF</code> type, the
806    * <i>typeName</i> parameter is ignored.
807    *
808    * <P><B>Note:</B> When reading the value of an out parameter, you
809    * must use the getter method whose Java type corresponds to the
810    * parameter's registered SQL type.
811    *
812    * @param paramIndex the first parameter is 1, the second is 2,...
813    * @param sqlType a value from {@link java.sql.Types}
814    * @param typeName the fully-qualified name of an SQL structured type
815    * @exception SQLException if a database access error occurs
816    * @see Types
817    * @since 1.2
818    *
819    * Note: Not supporting as it is for UDTs / Ref
820    */

821
822   public synchronized void registerOutParameter(int paramIndex, int sqlType, String JavaDoc typeName) throws
823       SQLException {
824     DException dex = new DException("DSE16",
825                                     new Object JavaDoc[] {"registerOutParameter"});
826     throw dex.getSqlException(connection.getLocale());
827   }
828
829
830   /**
831    * Registers the OUT parameter named
832    * <code>parameterName</code> to the JDBC type
833    * <code>sqlType</code>. All OUT parameters must be registered
834    * before a stored procedure is executed.
835    * <p>
836    * The JDBC type specified by <code>sqlType</code> for an OUT
837    * parameter determines the Java type that must be used
838    * in the <code>get</code> method to read the value of that parameter.
839    * <p>
840    * If the JDBC type expected to be returned to this output parameter
841    * is specific to this particular database, <code>sqlType</code>
842    * should be <code>java.sql.Types.OTHER</code>. The method
843    * {@link #getObject} retrieves the value.
844    * @param parameterName the name of the parameter
845    * @param sqlType the JDBC type code defined by <code>java.sql.Types</code>.
846    * If the parameter is of JDBC type <code>NUMERIC</code>
847    * or <code>DECIMAL</code>, the version of
848    * <code>registerOutParameter</code> that accepts a scale value
849    * should be used.
850    * @exception SQLException if a database access error occurs
851    * @since 1.4
852    * @see Types
853    */

854
855   public synchronized void registerOutParameter(String JavaDoc parameterName, int sqlType) throws
856       SQLException {
857     registerOutParameter(parameterName, new SQLType(sqlType));
858   }
859
860   /**
861    * Registers the parameter named
862    * <code>parameterName</code> to be of JDBC type
863    * <code>sqlType</code>. This method must be called
864    * before a stored procedure is executed.
865    * <p>
866    * The JDBC type specified by <code>sqlType</code> for an OUT
867    * parameter determines the Java type that must be used
868    * in the <code>get</code> method to read the value of that parameter.
869    * <p>
870    * This version of <code>registerOutParameter</code> should be
871    * used when the parameter is of JDBC type <code>NUMERIC</code>
872    * or <code>DECIMAL</code>.
873    * @param parameterName the name of the parameter
874    * @param sqlType SQL type code defined by <code>java.sql.Types</code>.
875    * @param scale the desired number of digits to the right of the
876    * decimal point. It must be greater than or equal to zero.
877    * @exception SQLException if a database access error occurs
878    * @since 1.4
879    * @see Types
880    */

881
882   public synchronized void registerOutParameter(String JavaDoc parameterName, int sqlType, int scale) throws
883       SQLException {
884     registerOutParameter(parameterName, new SQLType(sqlType, scale));
885   }
886
887   /**
888    * Registers the designated output parameter. This version of
889    * the method <code>registerOutParameter</code>
890    * should be used for a user-named or REF output parameter. Examples
891    * of user-named types include: STRUCT, DISTINCT, JAVA_OBJECT, and
892    * named array types.
893    *
894    * Before executing a stored procedure call, you must explicitly
895    * call <code>registerOutParameter</code> to register the type from
896    * <code>java.sql.Types</code> for each
897    * OUT parameter. For a user-named parameter the fully-qualified SQL
898    * type name of the parameter should also be given, while a REF
899    * parameter requires that the fully-qualified type name of the
900    * referenced type be given. A JDBC driver that does not need the
901    * type code and type name information may ignore it. To be portable,
902    * however, applications should always provide these values for
903    * user-named and REF parameters.
904    *
905    * Although it is intended for user-named and REF parameters,
906    * this method may be used to register a parameter of any JDBC type.
907    * If the parameter does not have a user-named or REF type, the
908    * typeName parameter is ignored.
909    *
910    * <P><B>Note:</B> When reading the value of an out parameter, you
911        * must use the <code>getXXX</code> method whose Java type XXX corresponds to the
912    * parameter's registered SQL type.
913    *
914    * @param parameterName the name of the parameter
915    * @param sqlType a value from {@link java.sql.Types}
916    * @param typeName the fully-qualified name of an SQL structured type
917    * @exception SQLException if a database access error occurs
918    * @see Types
919    * @since 1.4
920    *
921    * Note: Not Supporting as it is used for UDTs / Ref
922    */

923
924   public synchronized void registerOutParameter(String JavaDoc parameterName, int sqlType,
925                                    String JavaDoc typeName) throws SQLException {
926     DException dex = new DException("DSE16",
927                                     new Object JavaDoc[] {"registerOutParameter"});
928     throw dex.getSqlException(connection.getLocale());
929   }
930
931   /**
932    * Retrieves the value of the designated JDBC <code>DATALINK</code> parameter as a
933    * <code>java.net.URL</code> object.
934    *
935    * @param parameterIndex the first parameter is 1, the second is 2,...
936    * @return a <code>java.net.URL</code> object that represents the
937    * JDBC <code>DATALINK</code> value used as the designated
938    * parameter
939    * @exception SQLException if a database access error occurs,
940    * or if the URL being returned is
941    * not a valid URL on the Java platform
942    * @see #setURL
943    * @since 1.4
944    * DATALINK
945    */

946   public synchronized java.net.URL JavaDoc getURL(int parameterIndex) throws SQLException {
947     try {
948       isValidOUTParameterIndex(parameterIndex);
949       checkTypeEqual(parameterIndex, 70 /*Types.DATALINK*/, -1);
950       String JavaDoc url = (String JavaDoc) Utilities.convertObject(outParameter[parameterIndex -
951           1], Types.CHAR);
952       if (url == null)
953         return null;
954       return new java.net.URL JavaDoc(url);
955     }
956     catch (Exception JavaDoc E) {
957       throw new DException("DSE538",null).getSqlException(connection.getLocale());
958     }
959   }
960
961   /**
962    * Sets the designated parameter to the given <code>java.net.URL</code> object.
963    * The driver converts this to an SQL <code>DATALINK</code> value when
964    * it sends it to the database.
965    *
966    * @param parameterName the name of the parameter
967    * @param val the parameter value
968    * @exception SQLException if a database access error occurs,
969    * or if a URL is malformed
970    * @see #getURL
971    * @since 1.4
972    *
973    * @todo setURL 1.4
974    */

975   public synchronized void setURL(String JavaDoc parameterName, java.net.URL JavaDoc val) throws
976       SQLException {
977     DException dex = new DException("DSE16", new Object JavaDoc[] {"setURL"});
978     throw dex.getSqlException(connection.getLocale());
979   }
980
981   /**
982    * Sets the designated parameter to SQL <code>NULL</code>.
983    *
984    * <P><B>Note:</B> You must specify the parameter's SQL type.
985    *
986    * @param parameterName the name of the parameter
987    * @param sqlType the SQL type code defined in <code>java.sql.Types</code>
988    * @exception SQLException if a database access error occurs
989    * @since 1.4
990    */

991
992   public synchronized void setNull(String JavaDoc parameterName, int sqlType) throws SQLException {
993     setObject(parameterName, null, sqlType);
994   }
995
996   /**
997    * Sets the designated parameter to SQL <code>NULL</code>.
998    * This version of the method <code>setNull</code> should
999    * be used for user-defined types and REF type parameters. Examples
1000   * of user-defined types include: STRUCT, DISTINCT, JAVA_OBJECT, and
1001   * named array types.
1002   *
1003   * <P><B>Note:</B> To be portable, applications must give the
1004   * SQL type code and the fully-qualified SQL type name when specifying
1005   * a NULL user-defined or REF parameter. In the case of a user-defined type
1006   * the name is the type name of the parameter itself. For a REF
1007   * parameter, the name is the type name of the referenced type. If
1008   * a JDBC driver does not need the type code or type name information,
1009   * it may ignore it.
1010   *
1011   * Although it is intended for user-defined and Ref parameters,
1012   * this method may be used to set a null parameter of any JDBC type.
1013   * If the parameter does not have a user-defined or REF type, the given
1014   * typeName is ignored.
1015   *
1016   *
1017   * @param parameterName the name of the parameter
1018   * @param sqlType a value from <code>java.sql.Types</code>
1019   * @param typeName the fully-qualified name of an SQL user-defined type;
1020   * ignored if the parameter is not a user-defined type or
1021   * SQL <code>REF</code> value
1022   * @exception SQLException if a database access error occurs
1023   * @since 1.4
1024   */

1025
1026  public synchronized void setNull(String JavaDoc parameterName, int sqlType, String JavaDoc typeName) throws SQLException {
1027    setObject(parameterName, null, sqlType);
1028  }
1029
1030  /**
1031   * Sets the designated parameter to the given Java <code>boolean</code> value.
1032   * The driver converts this
1033   * to an SQL <code>BIT</code> value when it sends it to the database.
1034   *
1035   * @param parameterName the name of the parameter
1036   * @param x the parameter value
1037   * @exception SQLException if a database access error occurs
1038   * @see #getBoolean
1039   * @since 1.4
1040   */

1041
1042  public synchronized void setBoolean(String JavaDoc parameterName, boolean x) throws SQLException {
1043    setObject(parameterName, Utilities.getBooleanValue(x));
1044  }
1045
1046  /**
1047   * Sets the designated parameter to the given Java <code>byte</code> value.
1048   * The driver converts this
1049   * to an SQL <code>TINYINT</code> value when it sends it to the database.
1050   *
1051   * @param parameterName the name of the parameter
1052   * @param x the parameter value
1053   * @exception SQLException if a database access error occurs
1054   * @see #getByte
1055   * @since 1.4
1056   */

1057  public synchronized void setByte(String JavaDoc parameterName, byte x) throws SQLException {
1058    setObject(parameterName, new Byte JavaDoc(x));
1059  }
1060
1061  /**
1062   * Sets the designated parameter to the given Java <code>short</code> value.
1063   * The driver converts this
1064   * to an SQL <code>SMALLINT</code> value when it sends it to the database.
1065   *
1066   * @param parameterName the name of the parameter
1067   * @param x the parameter value
1068   * @exception SQLException if a database access error occurs
1069   * @see #getShort
1070   * @since 1.4
1071   */

1072
1073  public synchronized void setShort(String JavaDoc parameterName, short x) throws SQLException {
1074    setObject(parameterName, new Short JavaDoc(x));
1075  }
1076
1077  /**
1078   * Sets the designated parameter to the given Java <code>int</code> value.
1079   * The driver converts this
1080   * to an SQL <code>INTEGER</code> value when it sends it to the database.
1081   *
1082   * @param parameterName the name of the parameter
1083   * @param x the parameter value
1084   * @exception SQLException if a database access error occurs
1085   * @see #getInt
1086   * @since 1.4
1087   */

1088
1089  public synchronized void setInt(String JavaDoc parameterName, int x) throws SQLException {
1090    setObject(parameterName, new Integer JavaDoc(x));
1091  }
1092
1093  /**
1094   * Sets the designated parameter to the given Java <code>long</code> value.
1095   * The driver converts this
1096   * to an SQL <code>BIGINT</code> value when it sends it to the database.
1097   *
1098   * @param parameterName the name of the parameter
1099   * @param x the parameter value
1100   * @exception SQLException if a database access error occurs
1101   * @see #getLong
1102   * @since 1.4
1103   */

1104
1105  public synchronized void setLong(String JavaDoc parameterName, long x) throws SQLException {
1106    setObject(parameterName, new Long JavaDoc(x));
1107  }
1108
1109  /**
1110   * Sets the designated parameter to the given Java <code>float</code> value.
1111   * The driver converts this
1112   * to an SQL <code>FLOAT</code> value when it sends it to the database.
1113   *
1114   * @param parameterName the name of the parameter
1115   * @param x the parameter value
1116   * @exception SQLException if a database access error occurs
1117   * @see #getFloat
1118   * @since 1.4
1119   */

1120
1121  public synchronized void setFloat(String JavaDoc parameterName, float x) throws SQLException {
1122    setObject(parameterName, new Float JavaDoc(x));
1123  }
1124
1125  /**
1126   * Sets the designated parameter to the given Java <code>double</code> value.
1127   * The driver converts this
1128   * to an SQL <code>DOUBLE</code> value when it sends it to the database.
1129   *
1130   * @param parameterName the name of the parameter
1131   * @param x the parameter value
1132   * @exception SQLException if a database access error occurs
1133   * @see #getDouble
1134   * @since 1.4
1135   */

1136
1137  public synchronized void setDouble(String JavaDoc parameterName, double x) throws SQLException {
1138    setObject(parameterName, new Double JavaDoc(x));
1139  }
1140
1141  /**
1142   * Sets the designated parameter to the given
1143   * <code>java.math.BigDecimal</code> value.
1144   * The driver converts this to an SQL <code>NUMERIC</code> value when
1145   * it sends it to the database.
1146   *
1147   * @param parameterName the name of the parameter
1148   * @param x the parameter value
1149   * @exception SQLException if a database access error occurs
1150   * @see #getBigDecimal
1151   * @since 1.4
1152   */

1153
1154  public synchronized void setBigDecimal(String JavaDoc parameterName, BigDecimal x) throws
1155      SQLException {
1156    setObject(parameterName, x);
1157  }
1158
1159  /**
1160   * Sets the designated parameter to the given Java <code>String</code> value.
1161   * The driver converts this
1162   * to an SQL <code>VARCHAR</code> or <code>LONGVARCHAR</code> value
1163   * (depending on the argument's
1164   * size relative to the driver's limits on <code>VARCHAR</code> values)
1165   * when it sends it to the database.
1166   *
1167   * @param parameterName the name of the parameter
1168   * @param x the parameter value
1169   * @exception SQLException if a database access error occurs
1170   * @see #getString
1171   * @since 1.4
1172   */

1173
1174  public synchronized void setString(String JavaDoc parameterName, String JavaDoc x) throws SQLException {
1175    setObject(parameterName, x);
1176  }
1177
1178  /**
1179   * Sets the designated parameter to the given Java array of bytes.
1180   * The driver converts this to an SQL <code>VARBINARY</code> or
1181   * <code>LONGVARBINARY</code> (depending on the argument's size relative
1182   * to the driver's limits on <code>VARBINARY</code> values) when it sends
1183   * it to the database.
1184   *
1185   * @param parameterName the name of the parameter
1186   * @param x the parameter value
1187   * @exception SQLException if a database access error occurs
1188   * @see #getBytes
1189   * @since 1.4
1190   *
1191   * @todo setBytes(String paramName, byte x[])
1192   */

1193
1194  public synchronized void setBytes(String JavaDoc parameterName, byte x[]) throws SQLException {
1195    setObject(parameterName, x);
1196  }
1197
1198  /**
1199       * Sets the designated parameter to the given <code>java.sql.Date</code> value.
1200   * The driver converts this
1201   * to an SQL <code>DATE</code> value when it sends it to the database.
1202   *
1203   * @param parameterName the name of the parameter
1204   * @param x the parameter value
1205   * @exception SQLException if a database access error occurs
1206   * @see #getDate
1207   * @since 1.4
1208   */

1209
1210  public synchronized void setDate(String JavaDoc parameterName, Date JavaDoc x) throws SQLException {
1211    setObject(parameterName, x);
1212  }
1213
1214  /**
1215       * Sets the designated parameter to the given <code>java.sql.Time</code> value.
1216   * The driver converts this
1217   * to an SQL <code>TIME</code> value when it sends it to the database.
1218   *
1219   * @param parameterName the name of the parameter
1220   * @param x the parameter value
1221   * @exception SQLException if a database access error occurs
1222   * @see #getTime
1223   * @since 1.4
1224   */

1225
1226  public synchronized void setTime(String JavaDoc parameterName, java.sql.Time JavaDoc x) throws
1227      SQLException {
1228    setObject(parameterName, x);
1229  }
1230
1231  /**
1232   * Sets the designated parameter to the given <code>java.sql.Timestamp</code> value.
1233   * The driver
1234       * converts this to an SQL <code>TIMESTAMP</code> value when it sends it to the
1235   * database.
1236   *
1237   * @param parameterName the name of the parameter
1238   * @param x the parameter value
1239   * @exception SQLException if a database access error occurs
1240   * @see #getTimestamp
1241   * @since 1.4
1242   */

1243
1244  public synchronized void setTimestamp(String JavaDoc parameterName, java.sql.Timestamp JavaDoc x) throws
1245      SQLException {
1246    setObject(parameterName, x);
1247  }
1248
1249  /**
1250   * Sets the designated parameter to the given input stream, which will have
1251   * the specified number of bytes.
1252   * When a very large ASCII value is input to a <code>LONGVARCHAR</code>
1253   * parameter, it may be more practical to send it via a
1254   * <code>java.io.InputStream</code>. Data will be read from the stream
1255   * as needed until end-of-file is reached. The JDBC driver will
1256   * do any necessary conversion from ASCII to the database char format.
1257   *
1258   * <P><B>Note:</B> This stream object can either be a standard
1259   * Java stream object or your own subclass that implements the
1260   * standard interface.
1261   *
1262   * @param parameterName the name of the parameter
1263   * @param x the Java input stream that contains the ASCII parameter value
1264   * @param length the number of bytes in the stream
1265   * @exception SQLException if a database access error occurs
1266   * @since 1.4
1267   */

1268
1269  public synchronized void setAsciiStream(String JavaDoc parameterName, java.io.InputStream JavaDoc x,
1270                             int length) throws SQLException {
1271    byte[] bytes = new byte[length];
1272    try {
1273      x.read(bytes, 0, length);
1274    }
1275    catch (java.io.IOException JavaDoc E) {
1276      DException dex = new DException("DSE356", null);
1277      throw dex.getSqlException(connection.getLocale());
1278    }
1279    setObject(parameterName, bytes);
1280  }
1281
1282  /**
1283   * Sets the designated parameter to the given input stream, which will have
1284   * the specified number of bytes.
1285   * When a very large binary value is input to a <code>LONGVARBINARY</code>
1286   * parameter, it may be more practical to send it via a
1287       * <code>java.io.InputStream</code> object. The data will be read from the stream
1288   * as needed until end-of-file is reached.
1289   *
1290   * <P><B>Note:</B> This stream object can either be a standard
1291   * Java stream object or your own subclass that implements the
1292   * standard interface.
1293   *
1294   * @param parameterName the name of the parameter
1295   * @param x the java input stream which contains the binary parameter value
1296   * @param length the number of bytes in the stream
1297   * @exception SQLException if a database access error occurs
1298   * @since 1.4
1299   */

1300
1301  public synchronized void setBinaryStream(String JavaDoc parameterName, java.io.InputStream JavaDoc x,
1302                              int length) throws SQLException {
1303    byte[] bytes = new byte[length];
1304    try {
1305      x.read(bytes, 0, length);
1306    }
1307    catch (java.io.IOException JavaDoc E) {
1308      DException dex = new DException("DSE356", null);
1309      throw dex.getSqlException(connection.getLocale());
1310    }
1311    setObject(parameterName, bytes);
1312  }
1313
1314  /**
1315       * Sets the value of the designated parameter with the given object. The second
1316   * argument must be an object type; for integral values, the
1317   * <code>java.lang</code> equivalent objects should be used.
1318   *
1319   * <p>The given Java object will be converted to the given targetSqlType
1320   * before being sent to the database.
1321   *
1322   * If the object has a custom mapping (is of a class implementing the
1323   * interface <code>SQLData</code>),
1324   * the JDBC driver should call the method <code>SQLData.writeSQL</code> to write it
1325   * to the SQL data stream.
1326   * If, on the other hand, the object is of a class implementing
1327       * <code>Ref</code>, <code>Blob</code>, <code>Clob</code>, <code>Struct</code>,
1328   * or <code>Array</code>, the driver should pass it to the database as a
1329   * value of the corresponding SQL type.
1330   * <P>
1331   * Note that this method may be used to pass datatabase-
1332   * specific abstract data types.
1333   *
1334   * @param parameterName the name of the parameter
1335   * @param x the object containing the input parameter value
1336   * @param targetSqlType the SQL type (as defined in java.sql.Types) to be
1337   * sent to the database. The scale argument may further qualify this type.
1338   * @param scale for java.sql.Types.DECIMAL or java.sql.Types.NUMERIC types,
1339       * this is the number of digits after the decimal point. For all other
1340   * types, this value will be ignored.
1341   * @exception SQLException if a database access error occurs
1342   * @see Types
1343   * @see #getObject
1344   * @since 1.4
1345   */

1346
1347  public synchronized void setObject(String JavaDoc parameterName, Object JavaDoc x, int targetSqlType,
1348                        int scale) throws SQLException {
1349    try {
1350      setObject(parameterName,
1351                Utilities.convertObject(x, new SQLType(targetSqlType, scale)));
1352    }
1353    catch (DException e) {
1354      throw e.getSqlException(connection.getLocale());
1355    }
1356  }
1357
1358  /**
1359   * Sets the value of the designated parameter with the given object.
1360   * This method is like the method <code>setObject</code>
1361   * above, except that it assumes a scale of zero.
1362   *
1363   * @param parameterName the name of the parameter
1364   * @param x the object containing the input parameter value
1365   * @param targetSqlType the SQL type (as defined in java.sql.Types) to be
1366   * sent to the database
1367   * @exception SQLException if a database access error occurs
1368   * @see #getObject
1369   * @since 1.4
1370   */

1371  public void setObject(String JavaDoc parameterName, Object JavaDoc x, int targetSqlType) throws
1372      SQLException {
1373    try {
1374      setObject(parameterName,
1375                Utilities.convertObject(x, new SQLType(targetSqlType)));
1376    }
1377    catch (DException e) {
1378      throw e.getSqlException(connection.getLocale());
1379    }
1380  }
1381
1382  /**
1383   * Sets the value of the designated parameter with the given object.
1384   * The second parameter must be of type <code>Object</code>; therefore, the
1385       * <code>java.lang</code> equivalent objects should be used for built-in types.
1386   *
1387   * <p>The JDBC specification specifies a standard mapping from
1388   * Java <code>Object</code> types to SQL types. The given argument
1389   * will be converted to the corresponding SQL type before being
1390   * sent to the database.
1391   *
1392   * <p>Note that this method may be used to pass datatabase-
1393   * specific abstract data types, by using a driver-specific Java
1394   * type.
1395   *
1396       * If the object is of a class implementing the interface <code>SQLData</code>,
1397   * the JDBC driver should call the method <code>SQLData.writeSQL</code>
1398   * to write it to the SQL data stream.
1399   * If, on the other hand, the object is of a class implementing
1400       * <code>Ref</code>, <code>Blob</code>, <code>Clob</code>, <code>Struct</code>,
1401   * or <code>Array</code>, the driver should pass it to the database as a
1402   * value of the corresponding SQL type.
1403   * <P>
1404       * This method throws an exception if there is an ambiguity, for example, if the
1405       * object is of a class implementing more than one of the interfaces named above.
1406   *
1407   * @param parameterName the name of the parameter
1408   * @param x the object containing the input parameter value
1409   * @exception SQLException if a database access error occurs or if the given
1410   * <code>Object</code> parameter is ambiguous
1411   * @see #getObject
1412   * @since 1.4
1413   */

1414
1415  public synchronized void setObject(String JavaDoc parameterName, Object JavaDoc x) throws SQLException {
1416    if (flagIndexParameterUsed) {
1417      DException dex = new DException("DSE212", null);
1418      throw dex.getSqlException(connection.getLocale());
1419    }
1420    if (parameterMap == null)
1421      parameterMap = new HashMap(parametersCount);
1422    parameterMap.put(parameterName, x);
1423    flagNamedParameterUsed = true;
1424  }
1425
1426  /**
1427   * Sets the designated parameter to the given <code>Reader</code>
1428   * object, which is the given number of characters long.
1429   * When a very large UNICODE value is input to a <code>LONGVARCHAR</code>
1430   * parameter, it may be more practical to send it via a
1431   * <code>java.io.Reader</code> object. The data will be read from the stream
1432   * as needed until end-of-file is reached. The JDBC driver will
1433   * do any necessary conversion from UNICODE to the database char format.
1434   *
1435   * <P><B>Note:</B> This stream object can either be a standard
1436   * Java stream object or your own subclass that implements the
1437   * standard interface.
1438   *
1439   * @param parameterName the name of the parameter
1440   * @param reader the <code>java.io.Reader</code> object that
1441   * contains the UNICODE data used as the designated parameter
1442   * @param length the number of characters in the stream
1443   * @exception SQLException if a database access error occurs
1444   * @since 1.4
1445   */

1446
1447  public synchronized void setCharacterStream(String JavaDoc parameterName, java.io.Reader JavaDoc reader,
1448                                 int length) throws SQLException {
1449    char[] bytes = new char[length];
1450    try {
1451      reader.read(bytes, 0, length);
1452      setObject(parameterName, Utilities.convertCharsToBytes(bytes));
1453    }
1454    catch (Exception JavaDoc E) {
1455      DException dex = new DException("DSE356", null);
1456      throw dex.getSqlException(connection.getLocale());
1457    }
1458  }
1459
1460  /**
1461       * Sets the designated parameter to the given <code>java.sql.Date</code> value,
1462   * using the given <code>Calendar</code> object. The driver uses
1463       * the <code>Calendar</code> object to construct an SQL <code>DATE</code> value,
1464   * which the driver then sends to the database. With a
1465   * a <code>Calendar</code> object, the driver can calculate the date
1466   * taking into account a custom timezone. If no
1467   * <code>Calendar</code> object is specified, the driver uses the default
1468   * timezone, which is that of the virtual machine running the application.
1469   *
1470   * @param parameterName the name of the parameter
1471   * @param x the parameter value
1472   * @param cal the <code>Calendar</code> object the driver will use
1473   * to construct the date
1474   * @exception SQLException if a database access error occurs
1475   * @see #getDate
1476   * @since 1.4
1477   */

1478
1479  public synchronized void setDate(String JavaDoc parameterName, java.sql.Date JavaDoc x, Calendar cal) throws
1480      SQLException {
1481    cal.setTime(x);
1482    java.sql.Date JavaDoc date = new com.daffodilwoods.daffodildb.utils.DBDate(cal.getTime().getTime());
1483    setObject(parameterName, date);
1484  }
1485
1486  /**
1487       * Sets the designated parameter to the given <code>java.sql.Time</code> value,
1488   * using the given <code>Calendar</code> object. The driver uses
1489       * the <code>Calendar</code> object to construct an SQL <code>TIME</code> value,
1490   * which the driver then sends to the database. With a
1491   * a <code>Calendar</code> object, the driver can calculate the time
1492   * taking into account a custom timezone. If no
1493   * <code>Calendar</code> object is specified, the driver uses the default
1494   * timezone, which is that of the virtual machine running the application.
1495   *
1496   * @param parameterName the name of the parameter
1497   * @param x the parameter value
1498   * @param cal the <code>Calendar</code> object the driver will use
1499   * to construct the time
1500   * @exception SQLException if a database access error occurs
1501   * @see #getTime
1502   * @since 1.4
1503   */

1504
1505  public synchronized void setTime(String JavaDoc parameterName, java.sql.Time JavaDoc x, Calendar cal) throws
1506      SQLException {
1507    cal.setTime(x);
1508    Time time = new Time(cal.getTime().getTime());
1509    setObject(parameterName, time);
1510  }
1511
1512  /**
1513   * Sets the designated parameter to the given <code>java.sql.Timestamp</code> value,
1514   * using the given <code>Calendar</code> object. The driver uses
1515   * the <code>Calendar</code> object to construct an SQL <code>TIMESTAMP</code> value,
1516   * which the driver then sends to the database. With a
1517   * a <code>Calendar</code> object, the driver can calculate the timestamp
1518   * taking into account a custom timezone. If no
1519   * <code>Calendar</code> object is specified, the driver uses the default
1520   * timezone, which is that of the virtual machine running the application.
1521   *
1522   * @param parameterName the name of the parameter
1523   * @param x the parameter value
1524   * @param cal the <code>Calendar</code> object the driver will use
1525   * to construct the timestamp
1526   * @exception SQLException if a database access error occurs
1527   * @see #getTimestamp
1528   * @since 1.4
1529   */

1530
1531  public synchronized void setTimestamp(String JavaDoc parameterName, java.sql.Timestamp JavaDoc x,
1532                           Calendar cal) throws SQLException {
1533    cal.setTime(x);
1534    Timestamp timeStamp = new Timestamp(cal.getTime().getTime());
1535    setObject(parameterName, timeStamp);
1536  }
1537
1538  /**
1539   * Retrieves the value of a JDBC <code>CHAR</code>, <code>VARCHAR</code>,
1540   * or <code>LONGVARCHAR</code> parameter as a <code>String</code> in
1541   * the Java programming language.
1542   * <p>
1543   * For the fixed-length type JDBC <code>CHAR</code>,
1544   * the <code>String</code> object
1545   * returned has exactly the same value the JDBC
1546   * <code>CHAR</code> value had in the
1547   * database, including any padding added by the database.
1548   * @param parameterName the name of the parameter
1549       * @return the parameter value. If the value is SQL <code>NULL</code>, the result
1550   * is <code>null</code>.
1551   * @exception SQLException if a database access error occurs
1552   * @see #setString
1553   * @since 1.4
1554   */

1555
1556  public synchronized String JavaDoc getString(String JavaDoc parameterName) throws SQLException {
1557    isValidOUTParameterName(parameterName);
1558    checkTypeEqual(parameterName, "String");
1559    return parameterMap.get(parameterName) == null ? null :
1560        parameterMap.get(parameterName).toString();
1561  }
1562
1563  /**
1564   * Retrieves the value of a JDBC <code>BIT</code> parameter as a
1565   * <code>boolean</code> in the Java programming language.
1566   * @param parameterName the name of the parameter
1567   * @return the parameter value. If the value is SQL <code>NULL</code>, the result
1568   * is <code>false</code>.
1569   * @exception SQLException if a database access error occurs
1570   * @see #setBoolean
1571   * @since 1.4
1572   */

1573
1574  public synchronized boolean getBoolean(String JavaDoc parameterName) throws SQLException {
1575    isValidOUTParameterName(parameterName);
1576    checkTypeEqual(parameterName, Types.BIT, -1);
1577    try {
1578      Boolean JavaDoc bool = (Boolean JavaDoc) Utilities.convertObject(parameterMap.get(
1579          parameterName), Types.BIT);
1580      return bool == null ? false : bool.booleanValue();
1581    }
1582    catch (DException e) {
1583      throw e.getSqlException(connection.getLocale());
1584    }
1585  }
1586
1587  /**
1588   * Retrieves the value of a JDBC <code>TINYINT</code> parameter as a <code>byte</code>
1589   * in the Java programming language.
1590   * @param parameterName the name of the parameter
1591   * @return the parameter value. If the value is SQL <code>NULL</code>, the result
1592   * is <code>0</code>.
1593   * @exception SQLException if a database access error occurs
1594   * @see #setByte
1595   * @since 1.4
1596   */

1597
1598  public synchronized byte getByte(String JavaDoc parameterName) throws SQLException {
1599    isValidOUTParameterName(parameterName);
1600    checkTypeEqual(parameterName, Types.TINYINT, -1);
1601    try {
1602      Integer JavaDoc bool = (Integer JavaDoc) Utilities.convertObject(parameterMap.get(
1603          parameterName), Types.TINYINT);
1604      return bool == null ? 0 : bool.byteValue();
1605    }
1606    catch (DException e) {
1607      throw e.getSqlException(connection.getLocale());
1608    }
1609  }
1610
1611  /**
1612   * Retrieves the value of a JDBC <code>SMALLINT</code> parameter as a <code>short</code>
1613   * in the Java programming language.
1614   * @param parameterName the name of the parameter
1615   * @return the parameter value. If the value is SQL <code>NULL</code>, the result
1616   * is <code>0</code>.
1617   * @exception SQLException if a database access error occurs
1618   * @see #setShort
1619   * @since 1.4
1620   */

1621
1622  public synchronized short getShort(String JavaDoc parameterName) throws SQLException {
1623    isValidOUTParameterName(parameterName);
1624    checkTypeEqual(parameterName, Types.SMALLINT, -1);
1625    try {
1626      Integer JavaDoc bool = (Integer JavaDoc) Utilities.convertObject(parameterMap.get(
1627          parameterName), Types.SMALLINT);
1628      return bool == null ? 0 : bool.shortValue();
1629    }
1630    catch (DException e) {
1631      throw e.getSqlException(connection.getLocale());
1632    }
1633  }
1634
1635  /**
1636   * Retrieves the value of a JDBC <code>INTEGER</code> parameter as an <code>int</code>
1637   * in the Java programming language.
1638   *
1639   * @param parameterName the name of the parameter
1640   * @return the parameter value. If the value is SQL <code>NULL</code>,
1641   * the result is <code>0</code>.
1642   * @exception SQLException if a database access error occurs
1643   * @see #setInt
1644   * @since 1.4
1645   */

1646
1647  public synchronized int getInt(String JavaDoc parameterName) throws SQLException {
1648    isValidOUTParameterName(parameterName);
1649    checkTypeEqual(parameterName, Types.INTEGER, -1);
1650    try {
1651      Integer JavaDoc bool = (Integer JavaDoc) Utilities.convertObject(parameterMap.get(
1652          parameterName), Types.INTEGER);
1653      return bool == null ? 0 : bool.intValue();
1654    }
1655    catch (DException e) {
1656      throw e.getSqlException(connection.getLocale());
1657    }
1658  }
1659
1660  /**
1661   * Retrieves the value of a JDBC <code>BIGINT</code> parameter as a <code>long</code>
1662   * in the Java programming language.
1663   *
1664   * @param parameterName the name of the parameter
1665   * @return the parameter value. If the value is SQL <code>NULL</code>,
1666   * the result is <code>0</code>.
1667   * @exception SQLException if a database access error occurs
1668   * @see #setLong
1669   * @since 1.4
1670   */

1671
1672  public synchronized long getLong(String JavaDoc parameterName) throws SQLException {
1673    isValidOUTParameterName(parameterName);
1674    checkTypeEqual(parameterName, Types.BIGINT, -1);
1675    try {
1676      Long JavaDoc bool = (Long JavaDoc) Utilities.convertObject(parameterMap.get(parameterName),
1677                                                 Types.BIGINT);
1678      return bool == null ? 0 : bool.longValue();
1679    }
1680    catch (DException e) {
1681      throw e.getSqlException(connection.getLocale());
1682    }
1683  }
1684
1685  /**
1686   * Retrieves the value of a JDBC <code>FLOAT</code> parameter as a <code>float</code>
1687   * in the Java programming language.
1688   * @param parameterName the name of the parameter
1689   * @return the parameter value. If the value is SQL <code>NULL</code>,
1690   * the result is <code>0</code>.
1691   * @exception SQLException if a database access error occurs
1692   * @see #setFloat
1693   * @since 1.4
1694   */

1695
1696  public synchronized float getFloat(String JavaDoc parameterName) throws SQLException {
1697    isValidOUTParameterName(parameterName);
1698    checkTypeEqual(parameterName, Types.FLOAT, -1);
1699    try {
1700      Float JavaDoc bool = (Float JavaDoc) Utilities.convertObject(parameterMap.get(
1701          parameterName), Types.FLOAT);
1702      return bool == null ? 0 : bool.floatValue();
1703    }
1704    catch (DException e) {
1705      throw e.getSqlException(connection.getLocale());
1706    }
1707  }
1708
1709  /**
1710   * Retrieves the value of a JDBC <code>DOUBLE</code> parameter as a <code>double</code>
1711   * in the Java programming language.
1712   * @param parameterName the name of the parameter
1713   * @return the parameter value. If the value is SQL <code>NULL</code>,
1714   * the result is <code>0</code>.
1715   * @exception SQLException if a database access error occurs
1716   * @see #setDouble
1717   * @since 1.4
1718   */

1719
1720  public synchronized double getDouble(String JavaDoc parameterName) throws SQLException {
1721    isValidOUTParameterName(parameterName);
1722    checkTypeEqual(parameterName, Types.DOUBLE, -1);
1723    try {
1724      Double JavaDoc bool = (Double JavaDoc) Utilities.convertObject(parameterMap.get(
1725          parameterName), Types.DOUBLE);
1726      return bool == null ? 0 : bool.doubleValue();
1727    }
1728    catch (DException e) {
1729      throw e.getSqlException(connection.getLocale());
1730    }
1731  }
1732
1733  /**
1734       * Retrieves the value of a JDBC <code>BINARY</code> or <code>VARBINARY</code>
1735   * parameter as an array of <code>byte</code> values in the Java
1736   * programming language.
1737   * @param parameterName the name of the parameter
1738   * @return the parameter value. If the value is SQL <code>NULL</code>, the result is
1739   * <code>null</code>.
1740   * @exception SQLException if a database access error occurs
1741   * @see #setBytes
1742   * @since 1.4
1743   */

1744
1745  public synchronized byte[] getBytes(String JavaDoc parameterName) throws SQLException {
1746    isValidOUTParameterName(parameterName);
1747    checkTypeEqual(parameterName, "Binary");
1748    try {
1749      return (byte[]) Utilities.convertObject(parameterMap.get(parameterName),
1750                                              Types.BINARY);
1751    }
1752    catch (DException e) {
1753      throw e.getSqlException(connection.getLocale());
1754    }
1755  }
1756
1757  /**
1758   * Retrieves the value of a JDBC <code>DATE</code> parameter as a
1759   * <code>java.sql.Date</code> object.
1760   * @param parameterName the name of the parameter
1761   * @return the parameter value. If the value is SQL <code>NULL</code>, the result
1762   * is <code>null</code>.
1763   * @exception SQLException if a database access error occurs
1764   * @see #setDate
1765   * @since 1.4
1766   */

1767
1768  public synchronized java.sql.Date JavaDoc getDate(String JavaDoc parameterName) throws SQLException {
1769    return getDate(parameterName, null);
1770  }
1771
1772  /**
1773   * Retrieves the value of a JDBC <code>TIME</code> parameter as a
1774   * <code>java.sql.Time</code> object.
1775   * @param parameterName the name of the parameter
1776   * @return the parameter value. If the value is SQL <code>NULL</code>, the result
1777   * is <code>null</code>.
1778   * @exception SQLException if a database access error occurs
1779   * @see #setTime
1780   * @since 1.4
1781   */

1782
1783  public synchronized java.sql.Time JavaDoc getTime(String JavaDoc parameterName) throws SQLException {
1784    return getTime(parameterName, null);
1785  }
1786
1787  /**
1788   * Retrieves the value of a JDBC <code>TIMESTAMP</code> parameter as a
1789   * <code>java.sql.Timestamp</code> object.
1790   * @param parameterName the name of the parameter
1791   * @return the parameter value. If the value is SQL <code>NULL</code>, the result
1792   * is <code>null</code>.
1793   * @exception SQLException if a database access error occurs
1794   * @see #setTimestamp
1795   * @since 1.4
1796   */

1797
1798  public synchronized java.sql.Timestamp JavaDoc getTimestamp(String JavaDoc parameterName) throws
1799      SQLException {
1800    return getTimestamp(parameterName, null);
1801  }
1802
1803  /**
1804   * Retrieves the value of a parameter as an <code>Object</code> in the Java
1805   * programming language. If the value is an SQL <code>NULL</code>, the
1806   * driver returns a Java <code>null</code>.
1807   * <p>
1808   * This method returns a Java object whose type corresponds to the JDBC
1809   * type that was registered for this parameter using the method
1810   * <code>registerOutParameter</code>. By registering the target JDBC
1811   * type as <code>java.sql.Types.OTHER</code>, this method can be used
1812   * to read database-specific abstract data types.
1813   * @param parameterName the name of the parameter
1814   * @return A <code>java.lang.Object</code> holding the OUT parameter value.
1815   * @exception SQLException if a database access error occurs
1816   * @see Types
1817   * @see #setObject
1818   * @since 1.4
1819   */

1820
1821  public synchronized Object JavaDoc getObject(String JavaDoc parameterName) throws SQLException {
1822    return getObject(parameterName, null);
1823  }
1824
1825  /**
1826   * Retrieves the value of a JDBC <code>NUMERIC</code> parameter as a
1827   * <code>java.math.BigDecimal</code> object with as many digits to the
1828   * right of the decimal point as the value contains.
1829   * @param parameterName the name of the parameter
1830   * @return the parameter value in full precision. If the value is
1831   * SQL <code>NULL</code>, the result is <code>null</code>.
1832   * @exception SQLException if a database access error occurs
1833   * @see #setBigDecimal
1834   * @since 1.4
1835   */

1836
1837  public synchronized BigDecimal getBigDecimal(String JavaDoc parameterName) throws SQLException {
1838    isValidOUTParameterName(parameterName);
1839    checkTypeEqual(parameterName, Types.DECIMAL, -1);
1840    try {
1841      return (BigDecimal) Utilities.convertObject(parameterMap.get(
1842          parameterName), Types.DECIMAL);
1843    }
1844    catch (DException e) {
1845      throw e.getSqlException(connection.getLocale());
1846    }
1847  }
1848
1849  /**
1850   * Returns an object representing the value of OUT parameter
1851   * <code>i</code> and uses <code>map</code> for the custom
1852   * mapping of the parameter value.
1853   * <p>
1854   * This method returns a Java object whose type corresponds to the
1855   * JDBC type that was registered for this parameter using the method
1856   * <code>registerOutParameter</code>. By registering the target
1857   * JDBC type as <code>java.sql.Types.OTHER</code>, this method can
1858   * be used to read database-specific abstract data types.
1859   * @param parameterName the name of the parameter
1860   * @param map the mapping from SQL type names to Java classes
1861   * @return a <code>java.lang.Object</code> holding the OUT parameter value
1862   * @exception SQLException if a database access error occurs
1863   * @see #setObject
1864   * @since 1.4
1865   */

1866  public synchronized Object JavaDoc getObject(String JavaDoc parameterName, java.util.Map JavaDoc map) throws
1867      SQLException {
1868    isValidOUTParameterName(parameterName);
1869    SQLType sqlType = checkTypeEqual(parameterName, Types.OTHER, -1);
1870    /**@todo checkmap*/
1871    try {
1872      return Utilities.convertObject(parameterMap.get(parameterName),
1873                                     sqlType.getType());
1874    }
1875    catch (DException e) {
1876      throw e.getSqlException(connection.getLocale());
1877    }
1878  }
1879
1880  /**
1881   * Retrieves the value of a JDBC <code>REF(&lt;structured-type&gt;)</code>
1882   * parameter as a {@link Ref} object in the Java programming language.
1883   *
1884   * @param parameterName the name of the parameter
1885   * @return the parameter value as a <code>Ref</code> object in the
1886       * Java programming language. If the value was SQL <code>NULL</code>,
1887   * the value <code>null</code> is returned.
1888   * @exception SQLException if a database access error occurs
1889   * @since 1.4
1890   *
1891   * Note: not supporting as UDTs not allowed
1892   */

1893
1894  public synchronized Ref getRef(String JavaDoc parameterName) throws SQLException {
1895    DException dex = new DException("DSE16", new Object JavaDoc[] {"getRef"});
1896    throw dex.getSqlException(connection.getLocale());
1897  }
1898
1899  /**
1900   * Retrieves the value of a JDBC <code>BLOB</code> parameter as a
1901   * {@link Blob} object in the Java programming language.
1902   *
1903   * @param parameterName the name of the parameter
1904   * @return the parameter value as a <code>Blob</code> object in the
1905       * Java programming language. If the value was SQL <code>NULL</code>,
1906   * the value <code>null</code> is returned.
1907   * @exception SQLException if a database access error occurs
1908   * @since 1.4
1909   */

1910
1911  public synchronized Blob getBlob(String JavaDoc parameterName) throws SQLException {
1912    isValidOUTParameterName(parameterName);
1913    checkTypeEqual(parameterName, Types.BLOB, -1);
1914    try {
1915      return (Blob) Utilities.convertObject(parameterMap.get(parameterName),
1916                                            Types.BLOB);
1917    }
1918    catch (DException e) {
1919      throw e.getSqlException(connection.getLocale());
1920    }
1921  }
1922
1923  /**
1924   * Retrieves the value of a JDBC <code>CLOB</code> parameter as a
1925   * <code>Clob</code> object in the Java programming language.
1926   * @param parameterName the name of the parameter
1927   * @return the parameter value as a <code>Clob</code> object in the
1928       * Java programming language. If the value was SQL <code>NULL</code>,
1929   * the value <code>null</code> is returned.
1930   * @exception SQLException if a database access error occurs
1931   * @since 1.4
1932   */

1933
1934  public synchronized Clob getClob(String JavaDoc parameterName) throws SQLException {
1935    isValidOUTParameterName(parameterName);
1936    checkTypeEqual(parameterName, Types.CLOB, -1);
1937    try {
1938      return (Clob) Utilities.convertObject(parameterMap.get(parameterName),
1939                                            Types.CLOB);
1940    }
1941    catch (DException e) {
1942      throw e.getSqlException(connection.getLocale());
1943    }
1944  }
1945
1946  /**
1947   * Retrieves the value of a JDBC <code>ARRAY</code> parameter as an
1948   * {@link Array} object in the Java programming language.
1949   *
1950   * @param parameterName the name of the parameter
1951   * @return the parameter value as an <code>Array</code> object in
1952       * Java programming language. If the value was SQL <code>NULL</code>,
1953   * the value <code>null</code> is returned.
1954   * @exception SQLException if a database access error occurs
1955   * @since 1.4
1956   */

1957
1958  public synchronized Array getArray(String JavaDoc parameterName) throws SQLException {
1959    DException dex = new DException("DSE16", new Object JavaDoc[] {"getArray"});
1960    throw dex.getSqlException(connection.getLocale());
1961  }
1962
1963  /**
1964   * Retrieves the value of a JDBC <code>DATE</code> parameter as a
1965   * <code>java.sql.Date</code> object, using
1966   * the given <code>Calendar</code> object
1967   * to construct the date.
1968   * With a <code>Calendar</code> object, the driver
1969   * can calculate the date taking into account a custom timezone and locale.
1970   * If no <code>Calendar</code> object is specified, the driver uses the
1971   * default timezone and locale.
1972   *
1973   * @param parameterName the name of the parameter
1974   * @param cal the <code>Calendar</code> object the driver will use
1975   * to construct the date
1976   * @return the parameter value. If the value is SQL <code>NULL</code>,
1977   * the result is <code>null</code>.
1978   * @exception SQLException if a database access error occurs
1979   * @see #setDate
1980   * @since 1.4
1981   */

1982
1983  public synchronized java.sql.Date JavaDoc getDate(String JavaDoc parameterName, Calendar cal) throws
1984      SQLException {
1985    isValidOUTParameterName(parameterName);
1986    checkTypeEqual(parameterName, Types.DATE, -1);
1987    try {
1988      java.sql.Date JavaDoc date = (Date JavaDoc) Utilities.convertObject(parameterMap.get(
1989          parameterName), Types.DATE);
1990      if (date == null || cal == null)
1991        return date;
1992      cal.setTime(date);
1993      return new com.daffodilwoods.daffodildb.utils.DBDate(cal.getTime().getTime()
1994          /*cal.get(Calendar.YEAR),cal.get(Calendar.MONTH),cal.get(Calendar.DATE)*/);
1995    }
1996    catch (DException e) {
1997      throw e.getSqlException(connection.getLocale());
1998    }
1999  }
2000
2001  /**
2002   * Retrieves the value of a JDBC <code>TIME</code> parameter as a
2003   * <code>java.sql.Time</code> object, using
2004   * the given <code>Calendar</code> object
2005   * to construct the time.
2006   * With a <code>Calendar</code> object, the driver
2007   * can calculate the time taking into account a custom timezone and locale.
2008   * If no <code>Calendar</code> object is specified, the driver uses the
2009   * default timezone and locale.
2010   *
2011   * @param parameterName the name of the parameter
2012   * @param cal the <code>Calendar</code> object the driver will use
2013   * to construct the time
2014   * @return the parameter value; if the value is SQL <code>NULL</code>, the result is
2015   * <code>null</code>.
2016   * @exception SQLException if a database access error occurs
2017   * @see #setTime
2018   * @since 1.4
2019   */

2020
2021  public synchronized java.sql.Time JavaDoc getTime(String JavaDoc parameterName, Calendar cal) throws
2022      SQLException {
2023    try {
2024      isValidOUTParameterName(parameterName);
2025      checkTypeEqual(parameterName, Types.TIME, -1);
2026      Time tmObj = (Time) Utilities.convertObject(parameterMap.get(
2027          parameterName), Types.TIME);
2028      if (tmObj == null)
2029        return null;
2030      Date JavaDoc timeObject = new com.daffodilwoods.daffodildb.utils.DBDate(tmObj.getTime());
2031      if (cal == null) {
2032        Time time = new Time(timeObject.getTime());
2033        return time;
2034      }
2035      cal.setTime(timeObject);
2036      Time calTime = new Time(cal.getTime().getTime()
2037          /*cal.get(Calendar.HOUR),cal.get(Calendar.MINUTE),
2038                                       cal.get(Calendar.SECOND) */
);
2039      return calTime;
2040    }
2041    catch (Exception JavaDoc e) {
2042      DaffodilDBExceptionHandler.handle("", "", e, connection.getLocale());
2043      return null;
2044    }
2045  }
2046
2047  /**
2048   * Retrieves the value of a JDBC <code>TIMESTAMP</code> parameter as a
2049   * <code>java.sql.Timestamp</code> object, using
2050   * the given <code>Calendar</code> object to construct
2051   * the <code>Timestamp</code> object.
2052   * With a <code>Calendar</code> object, the driver
2053       * can calculate the timestamp taking into account a custom timezone and locale.
2054   * If no <code>Calendar</code> object is specified, the driver uses the
2055   * default timezone and locale.
2056   *
2057   *
2058   * @param parameterName the name of the parameter
2059   * @param cal the <code>Calendar</code> object the driver will use
2060   * to construct the timestamp
2061   * @return the parameter value. If the value is SQL <code>NULL</code>, the result is
2062   * <code>null</code>.
2063   * @exception SQLException if a database access error occurs
2064   * @see #setTimestamp
2065   * @since 1.4
2066   *
2067   */

2068
2069  public synchronized java.sql.Timestamp JavaDoc getTimestamp(String JavaDoc parameterName, Calendar cal) throws
2070      SQLException {
2071    try {
2072      isValidOUTParameterName(parameterName);
2073      checkTypeEqual(parameterName, Types.TIMESTAMP, -1);
2074      Timestamp tmObj = (Timestamp) Utilities.convertObject(parameterMap.get(
2075          parameterName), Types.TIMESTAMP);
2076      if (tmObj == null)
2077        return null;
2078      Date JavaDoc timeStamp = new com.daffodilwoods.daffodildb.utils.DBDate(tmObj.getTime());
2079      if (cal == null)
2080        return new Timestamp(timeStamp.getTime());
2081      cal.setTime(timeStamp);
2082      Timestamp calTimeStamp = new Timestamp(cal.getTime().getTime());
2083      return calTimeStamp;
2084    }
2085    catch (Exception JavaDoc e) {
2086      DaffodilDBExceptionHandler.handle("", "", e, connection.getLocale());
2087      return null;
2088    }
2089  }
2090
2091  /**
2092   * Retrieves the value of a JDBC <code>DATALINK</code> parameter as a
2093   * <code>java.net.URL</code> object.
2094   *
2095   * @param parameterName the name of the parameter
2096   * @return the parameter value as a <code>java.net.URL</code> object in the
2097   * Java programming language. If the value was SQL <code>NULL</code>, the
2098   * value <code>null</code> is returned.
2099   * @exception SQLException if a database access error occurs,
2100   * or if there is a problem with the URL
2101   * @see #setURL
2102   * @since 1.4
2103   */

2104
2105  public synchronized java.net.URL JavaDoc getURL(String JavaDoc parameterName) throws SQLException {
2106    DException dex = new DException("DSE16", new Object JavaDoc[] {"getURL"});
2107    throw dex.getSqlException(connection.getLocale());
2108  }
2109
2110  /**
2111   * @ todo
2112   * What this will do
2113   */

2114
2115  public synchronized void addBatch() throws SQLException {
2116    if(serverPreparedStatement.getQueryType() != _PreparedStatement.callstatement) {
2117      super.addBatch();
2118      return;
2119    }
2120    checkConnection();
2121    checkIfAllParametersSet();
2122    if (parameterBatch == null)
2123       parameterBatch = new ArrayList(4);
2124    if (flagNamedParameterUsed) {
2125       parameterBatch.add(parameterMap);
2126       parameterMap = new HashMap();
2127    }
2128    else{
2129       parameterBatch.add(parameters);
2130       parameters = new Object JavaDoc[parametersCount];
2131       parametersSet = new boolean[parametersCount];
2132       Arrays.fill(parametersSet, false);
2133    }
2134  }
2135
2136  public synchronized int[] executeBatch() throws SQLException {
2137    if(serverPreparedStatement.getQueryType() != _PreparedStatement.callstatement) {
2138      return super.executeBatch();
2139    }
2140    checkConnection();
2141    if (parameterBatch == null)
2142      return new int[0];
2143    createEnvironmentToExecute(false);
2144    outParameters = null;
2145    outParameter = null;
2146    outParameterMap = null;
2147    int size = parameterBatch.size();
2148    int[] abc = new int[size];
2149    java.util.Arrays.fill(abc, -3);
2150    Object JavaDoc obj = null;
2151    synchronized (connection){
2152
2153      for (int i = 0; i < size; i++) {
2154        try {
2155          Object JavaDoc o = parameterBatch.get(i);
2156          if (o instanceof HashMap) {
2157            obj = serverPreparedStatement.execute( (HashMap) o, queryTimeOut);
2158          }
2159          else
2160            obj = serverPreparedStatement.execute( (Object JavaDoc[]) parameterBatch.
2161                                                  get(
2162                i), queryTimeOut);
2163          CallResult callResult = (CallResult) obj;
2164          if (callResult.getResult()instanceof _SelectIterator) {
2165            DException dex = new DException("DSE401", null);
2166            throw dex.getSqlException(connection.getLocale());
2167          }
2168          abc[i] = callResult.getResult().hashCode();
2169          abc[i] = abc[i] == Integer.MIN_VALUE ? 0 : abc[i];
2170        }
2171        catch (DException E) {
2172          clearBatch();
2173          throw new BatchUpdateException(E.getMessage(), abc);
2174        }
2175      }
2176    }
2177    clearBatch();
2178    return abc;
2179  }
2180
2181  public synchronized ResultSet executeQuery() throws SQLException {
2182    if(serverPreparedStatement.getQueryType() != _PreparedStatement.callstatement) {
2183      return super.executeQuery();
2184    }
2185    execute();
2186    return resultSet;
2187  }
2188
2189  public synchronized int executeUpdate() throws SQLException {
2190    if(serverPreparedStatement.getQueryType() != _PreparedStatement.callstatement) {
2191      return super.executeUpdate();
2192    }
2193    execute();
2194    return updateCount;
2195  }
2196
2197  /**
2198   * @ todo: execute()
2199   * Note: this method will give multiple results but one OUT parameter Map
2200   */

2201  public synchronized boolean execute() throws SQLException {
2202    if(serverPreparedStatement.getQueryType() != _PreparedStatement.callstatement ) {
2203      return super.execute();
2204    }
2205
2206    checkConnection();
2207    writeToLog(query);
2208    createEnvironmentToExecute(true);
2209    checkIfAllParametersSet();
2210    if(userDefinedFunction && outParametersTypeMap == null ){
2211      DException dex = new DException("DSE1157", null);
2212      throw dex.getSqlException(connection.getLocale());
2213    }
2214
2215    outParameter = null;
2216    outParameters = null;
2217    outParameterMap = null;
2218    updateCount = -1;
2219    currentResultIndex = 0;
2220    resultSet = null;
2221
2222    Object JavaDoc result;
2223    try {
2224      synchronized (connection) {
2225        if (flagNamedParameterUsed) {
2226          /** @todo parameter name related work is pending
2227           * ==== After getting support for parameter name we can also check
2228           * parameter name in setObject method of parameter name
2229           * */

2230            result = serverPreparedStatement.execute(parameterMap, queryTimeOut);
2231        }
2232        else {
2233          if(userDefinedFunction){
2234            Object JavaDoc paramObj[] =new Object JavaDoc[parameters.length -1 ];
2235            System.arraycopy(parameters,1,paramObj,0,parameters.length -1 );
2236            result = serverPreparedStatement.execute(paramObj, queryTimeOut);
2237
2238          }
2239          else{
2240            result = serverPreparedStatement.execute(parameters, queryTimeOut);
2241          }
2242
2243        }
2244      }
2245    }
2246    catch (DException e) {
2247      throw e.getSqlException(connection.getLocale());
2248    }
2249    if (result == null) {
2250      executeResult = null;
2251      return false;
2252    }
2253    try {
2254      CallResult callResult = (CallResult) result;
2255      outParameters = callResult.getOUTParameters();
2256      if (outParameters instanceof HashMap)
2257        outParameterMap = (HashMap) outParameters;
2258      else
2259        outParameter = (Object JavaDoc[]) outParameters;
2260        /** UDF related work .. */
2261       if(userDefinedFunction) {
2262        outParameter = new Object JavaDoc[1];
2263         outParameter[0] = callResult.getResult();
2264         return true;
2265       }
2266
2267      if (callResult.getResult() == null) {
2268        executeResult = null;
2269        return false;
2270      }
2271
2272      executeResult = (Object JavaDoc[]) callResult.getResult();
2273      if (executeResult == null || executeResult[0] == null) {
2274        currentResultIndex = -2;
2275        updateCount = -1;
2276        resultSet = null;
2277        return false;
2278      }
2279      Object JavaDoc[] reqObject = DaffodilDBStatement.getRequiredObjectOfexecute(executeResult[0], resultSetConcurrency,maxRows);
2280      executeResult[0] = reqObject[0];
2281       if (executeResult[0] instanceof _RecordSetBuffer) {
2282        _RecordSetBuffer recordSetBuffer = (_RecordSetBuffer) executeResult[0];
2283        resultSet = new DaffodilDBResultSet(this);
2284        resultSet.setRecordSetBuffer(recordSetBuffer);
2285        int oldResultSetCon = resultSetConcurrency;
2286        resultSetConcurrency = reqObject[1].hashCode();
2287        if(oldResultSetCon != resultSetConcurrency )
2288          addWarning("the resultSet Concurency is set ResultSet.CONCUR_READ_ONLY " ) ;
2289        setResultSetAttributes();
2290        setRecordSetBufferAttributes(recordSetBuffer);
2291        resultSetConcurrency = oldResultSetCon;
2292        return true;
2293      }
2294      updateCount = executeResult[0].hashCode();
2295      updateCount = updateCount == Integer.MIN_VALUE ? 0 : updateCount;
2296      return false;
2297    }
2298    catch (DException dxe) {
2299      throw dxe.getSqlException(connection.getLocale());
2300    }
2301  }
2302
2303  /*-------------------- Private Methods For Callable Statement ----------------------*/
2304
2305  private void isValidOUTParameterName(String JavaDoc name) throws SQLException {
2306    checkStatementType();
2307    if (flagNamedParameterUsed == false || outParametersTypeMap.get(name) == null ||
2308        outParameterMap == null || ! (outParameterMap.containsKey(name))) {
2309      DException dex = new DException("DSE740", new Object JavaDoc[] {name,
2310                                      outParameterMap});
2311      throw dex.getSqlException(connection.getLocale());
2312    }
2313  }
2314
2315  private void isValidOUTParameterIndex(int index) throws SQLException {
2316     checkStatementType();
2317     checkValidParameterIndex(index);
2318    if (flagIndexParameterUsed == false || outParametersTypeMap == null||
2319        outParametersTypeMap.get(new Integer JavaDoc(index)) == null ||
2320        outParameter == null) {
2321      DException dex = new DException("DSE740", new Object JavaDoc[] {new Integer JavaDoc(index),
2322                                      outParameterMap});
2323      throw dex.getSqlException(connection.getLocale());
2324    }
2325  }
2326
2327  private void checkStatementType() throws SQLException {
2328    if (serverPreparedStatement.getQueryType() !=
2329        _PreparedStatement.callstatement) {
2330      DException ex = new DException("DSE8042", null);
2331      throw ex.getSqlException(connection.getLocale());
2332    }
2333  }
2334
2335  private void registerOutParameter(int parameterIndex, SQLType sqlType) throws
2336      SQLException {
2337    checkValidParameterIndex(parameterIndex);
2338    if (flagNamedParameterUsed == true) {
2339      DException dex = new DException("DSE212", null);
2340      throw dex.getSqlException(connection.getLocale());
2341    }
2342    if(outParametersTypeMap == null)
2343      outParametersTypeMap = new HashMap();
2344      outParametersTypeMap.put(new Integer JavaDoc(parameterIndex), sqlType);
2345    if(parametersSet[parameterIndex - 1]==false) {
2346      setNull(parameterIndex, sqlType.getType());
2347    }
2348  }
2349
2350  private void registerOutParameter(String JavaDoc parameterName, SQLType sqlType) throws
2351      SQLException {
2352    checkStatementType();
2353    if (flagIndexParameterUsed == true) {
2354      DException dex = new DException("DSE212", null);
2355      throw dex.getSqlException(connection.getLocale());
2356    }
2357    if (outParametersTypeMap == null)
2358      outParametersTypeMap = new HashMap();
2359    outParametersTypeMap.put(parameterName, sqlType);
2360    if(parameterMap.containsKey(parameterName)==false) {
2361      setNull(parameterName, sqlType.getType());
2362    }
2363  }
2364
2365  private SQLType checkTypeEqual(int parameterIndex, int type, int scale) throws SQLException {
2366    SQLType sqlType = (SQLType) outParametersTypeMap.get(new Integer JavaDoc(
2367        parameterIndex));
2368    return checkTypeEqual(sqlType, type, scale);
2369  }
2370
2371  private SQLType checkTypeEqual(String JavaDoc parameterName, int type, int scale) throws SQLException {
2372    SQLType sqlType = (SQLType) outParametersTypeMap.get(parameterName);
2373    return checkTypeEqual(sqlType, type, scale);
2374  }
2375
2376  private SQLType checkTypeEqual(SQLType sqlType, int type, int scale) throws SQLException {
2377    if (sqlType.isCompatibleTo(type, scale))
2378      return sqlType;
2379    DException dex = new DException("DSE1022", null);
2380    throw dex.getSqlException(connection.getLocale());
2381  }
2382
2383  private SQLType checkTypeEqual(int parameterIndex, String JavaDoc str) throws SQLException {
2384    SQLType sqlType = (SQLType) outParametersTypeMap.get(new Integer JavaDoc(
2385        parameterIndex));
2386    return checkTypeEqual(sqlType, str);
2387  }
2388
2389  private SQLType checkTypeEqual(String JavaDoc parameterName, String JavaDoc str) throws SQLException {
2390    SQLType sqlType = (SQLType) outParametersTypeMap.get(new Integer JavaDoc(
2391        parameterName));
2392    return checkTypeEqual(sqlType, str);
2393  }
2394
2395  private SQLType checkTypeEqual(SQLType sqlType, String JavaDoc str) throws SQLException {
2396    if (str.equalsIgnoreCase("string")) {
2397      if (sqlType.getType() == Types.CHAR || sqlType.getType() == Types.VARCHAR ||
2398          sqlType.getType() == Types.LONGVARCHAR)
2399        return sqlType;
2400    }
2401    else if (str.equalsIgnoreCase("binary")) {
2402      if (sqlType.getType() == Types.BINARY ||
2403          sqlType.getType() == Types.VARBINARY ||
2404          sqlType.getType() == Types.LONGVARBINARY)
2405        return sqlType;
2406    }
2407    DException dex = new DException("DSE1022", null);
2408    throw dex.getSqlException(connection.getLocale());
2409  }
2410
2411  public synchronized void setObject(int parameterIndex, Object JavaDoc x) throws SQLException {
2412    if (flagNamedParameterUsed) {
2413      DException dex = new DException("DSE212", null);
2414      throw dex.getSqlException(connection.getLocale());
2415    }
2416    super.setObject(parameterIndex, x);
2417    flagIndexParameterUsed = true;
2418  }
2419
2420  protected void checkIfAllParametersSet() throws SQLException{
2421    if(flagNamedParameterUsed && parameterMap.size()!=parametersCount) {
2422      DException dex = new DException("DSE1157", null);
2423      throw dex.getSqlException(connection.getLocale());
2424    }
2425    if(flagIndexParameterUsed) {
2426      boolean flag = true;
2427      for (int i = 0; flag && i < parametersCount; i++)
2428        flag = flag && parametersSet[i];
2429      if (flag == false) {
2430        DException dex = new DException("DSE1157", null);
2431        throw dex.getSqlException(connection.getLocale());
2432      }
2433    }
2434  }
2435
2436
2437protected void setPreparedStatement() throws SQLException {
2438      String JavaDoc queryForDB = changeQueryForDB(query).trim().toLowerCase();
2439      if(queryForDB.startsWith("?")) {
2440        int callIndex = queryForDB.indexOf("=");
2441        queryForDB = queryForDB.substring(callIndex +1);
2442        outParametersCount = 1;
2443        query = queryForDB;
2444        userDefinedFunction = true;
2445      }
2446
2447      try {
2448         if(autoGeneratedKeyType == _Connection.NOAUTOGENERATEDKEYS){
2449            serverPreparedStatement = connection.getServerConnection().
2450                getPreparedStatement(queryForDB,
2451                                     resultSetConcurrency ==
2452                                     ResultSet.CONCUR_UPDATABLE ?
2453                                     IteratorConstants.UPDATABLE :
2454                                     IteratorConstants.NONSCROLLABLE);
2455           }
2456
2457          else{
2458            serverPreparedStatement = connection.getServerConnection().
2459                getPreparedStatement(queryForDB,
2460                                     resultSetConcurrency ==
2461                                     ResultSet.CONCUR_UPDATABLE ?
2462                                     IteratorConstants.UPDATABLE :
2463                                     IteratorConstants.NONSCROLLABLE,autoGeneratedKeyType,autoGeneratedKeyParams);
2464          }
2465         parametersCount = serverPreparedStatement.getParameterMetaData().getParameterCount();
2466
2467        }catch (DException dxe) {
2468            throw dxe.getSqlException(connection.getLocale());
2469        }
2470        parametersSet = new boolean[parametersCount];
2471        parameters = new Object JavaDoc[parametersCount];
2472        Arrays.fill(parametersSet, false);
2473  }
2474}
2475
Popular Tags