KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > rmijdbc > RJCallableStatementServer


1  
2 /**
3  * RmiJdbc client/server JDBC Driver
4  * (C) GIE Dyade (Groupe BULL / INRIA Research Center) 1997
5  *
6  * @version 1.0
7  * @author Pierre-Yves Gibello (pierreyves.gibello@experlog.com)
8  */

9
10 package org.objectweb.rmijdbc;
11
12 import java.math.BigDecimal JavaDoc;
13 import java.rmi.*;
14 import java.rmi.server.Unreferenced JavaDoc;
15 import java.sql.*;
16 import java.util.Calendar JavaDoc;
17
18 /**
19  * <P>CallableStatement is used to execute SQL stored procedures.
20  *
21  * <P>JDBC provides a stored procedure SQL escape that allows stored
22  * procedures to be called in a standard way for all RDBMS's. This
23  * escape syntax has one form that includes a result parameter and one
24  * that does not. If used, the result parameter must be registered as
25  * an OUT parameter. The other parameters may be used for input,
26  * output or both. Parameters are refered to sequentially, by
27  * number. The first parameter is 1.
28  *
29  * <P><CODE>
30  * {?= call <procedure-name>[<arg1>,<arg2>, ...]}<BR>
31  * {call <procedure-name>[<arg1>,<arg2>, ...]}
32  * </CODE>
33  *
34  * <P>IN parameter values are set using the set methods inherited from
35  * PreparedStatement. The type of all OUT parameters must be
36  * registered prior to executing the stored procedure; their values
37  * are retrieved after execution via the get methods provided here.
38  *
39  * <P>A Callable statement may return a ResultSet or multiple
40  * ResultSets. Multiple ResultSets are handled using operations
41  * inherited from Statement.
42  *
43  * <P>For maximum portability, a call's ResultSets and update counts
44  * should be processed prior to getting the values of output
45  * parameters.
46  *
47  * @see Connection#prepareCall
48  * @see ResultSet
49  */

50 public class RJCallableStatementServer
51 extends RJPreparedStatementServer
52 implements RJCallableStatementInterface, Unreferenced JavaDoc {
53
54   java.sql.CallableStatement JavaDoc jdbcCallableStmt_;
55
56   public RJCallableStatementServer(java.sql.CallableStatement JavaDoc c)
57   throws java.rmi.RemoteException JavaDoc {
58     super(c);
59     jdbcCallableStmt_ = c;
60   }
61
62   public void unreferenced() { Runtime.getRuntime().gc(); }
63
64     /**
65      * Before executing a stored procedure call, you must explicitly
66      * call registerOutParameter to register the java.sql.Type of each
67      * out parameter.
68      *
69      * <P><B>Note:</B> When reading the value of an out parameter, you
70      * must use the getXXX method whose Java type XXX corresponds to the
71      * parameter's registered SQL type.
72      *
73      * @param parameterIndex the first parameter is 1, the second is 2,...
74      * @param sqlType SQL type code defined by java.sql.Types;
75      * for parameters of type Numeric or Decimal use the version of
76      * registerOutParameter that accepts a scale value
77      * @see Type
78      */

79   public void registerOutParameter(int parameterIndex, int sqlType)
80   throws RemoteException, SQLException {
81     jdbcCallableStmt_.registerOutParameter(parameterIndex, sqlType);
82   }
83
84     /**
85      * Use this version of registerOutParameter for registering
86      * Numeric or Decimal out parameters.
87      *
88      * <P><B>Note:</B> When reading the value of an out parameter, you
89      * must use the getXXX method whose Java type XXX corresponds to the
90      * parameter's registered SQL type.
91      *
92      * @param parameterIndex the first parameter is 1, the second is 2, ...
93      * @param sqlType use either java.sql.Type.NUMERIC or java.sql.Type.DECIMAL
94      * @param scale a value greater than or equal to zero representing the
95      * desired number of digits to the right of the decimal point
96      * @see Type
97      */

98   public void registerOutParameter(int parameterIndex, int sqlType, int scale)
99   throws RemoteException, SQLException {
100     jdbcCallableStmt_.registerOutParameter(parameterIndex, sqlType, scale);
101   }
102
103     /**
104      * An OUT parameter may have the value of SQL NULL; wasNull reports
105      * whether the last value read has this special value.
106      *
107      * <P><B>Note:</B> You must first call getXXX on a parameter to
108      * read its value and then call wasNull() to see if the value was
109      * SQL NULL.
110      *
111      * @return true if the last parameter read was SQL NULL
112      */

113   public boolean wasNull() throws RemoteException, SQLException {
114     return jdbcCallableStmt_.wasNull();
115   }
116
117     /**
118      * Get the value of a CHAR, VARCHAR, or LONGVARCHAR parameter as a Java String.
119      *
120      * @param parameterIndex the first parameter is 1, the second is 2, ...
121      * @return the parameter value; if the value is SQL NULL, the result is null
122      */

123   public String JavaDoc getString(int parameterIndex) throws RemoteException, SQLException {
124     return jdbcCallableStmt_.getString(parameterIndex);
125   }
126
127     /**
128      * Get the value of a BIT parameter as a Java boolean.
129      *
130      * @param parameterIndex the first parameter is 1, the second is 2, ...
131      * @return the parameter value; if the value is SQL NULL, the result is false
132      */

133   public boolean getBoolean(int parameterIndex) throws RemoteException, SQLException {
134     return jdbcCallableStmt_.getBoolean(parameterIndex);
135   }
136
137     /**
138      * Get the value of a TINYINT parameter as a Java byte.
139      *
140      * @param parameterIndex the first parameter is 1, the second is 2, ...
141      * @return the parameter value; if the value is SQL NULL, the result is 0
142      */

143   public byte getByte(int parameterIndex) throws RemoteException, SQLException {
144     return jdbcCallableStmt_.getByte(parameterIndex);
145   }
146
147     /**
148      * Get the value of a SMALLINT parameter as a Java short.
149      *
150      * @param parameterIndex the first parameter is 1, the second is 2, ...
151      * @return the parameter value; if the value is SQL NULL, the result is 0
152      */

153   public short getShort(int parameterIndex) throws RemoteException, SQLException {
154     return jdbcCallableStmt_.getShort(parameterIndex);
155   }
156
157     /**
158      * Get the value of an INTEGER parameter as a Java int.
159      *
160      * @param parameterIndex the first parameter is 1, the second is 2, ...
161      * @return the parameter value; if the value is SQL NULL, the result is 0
162      */

163   public int getInt(int parameterIndex) throws RemoteException, SQLException {
164     return jdbcCallableStmt_.getInt(parameterIndex);
165   }
166
167     /**
168      * Get the value of a BIGINT parameter as a Java long.
169      *
170      * @param parameterIndex the first parameter is 1, the second is 2, ...
171      * @return the parameter value; if the value is SQL NULL, the result is 0
172      */

173   public long getLong(int parameterIndex) throws RemoteException, SQLException {
174     return jdbcCallableStmt_.getLong(parameterIndex);
175   }
176
177     /**
178      * Get the value of a FLOAT parameter as a Java float.
179      *
180      * @param parameterIndex the first parameter is 1, the second is 2, ...
181      * @return the parameter value; if the value is SQL NULL, the result is 0
182      */

183   public float getFloat(int parameterIndex) throws RemoteException, SQLException {
184     return jdbcCallableStmt_.getFloat(parameterIndex);
185   }
186
187     /**
188      * Get the value of a DOUBLE parameter as a Java double.
189      *
190      * @param parameterIndex the first parameter is 1, the second is 2, ...
191      * @return the parameter value; if the value is SQL NULL, the result is 0
192      */

193   public double getDouble(int parameterIndex) throws RemoteException, SQLException {
194     return jdbcCallableStmt_.getDouble(parameterIndex);
195   }
196
197     /**
198      * Get the value of a NUMERIC parameter as a java.math.BigDecimal object.
199      *
200      * @param parameterIndex the first parameter is 1, the second is 2, ...
201      * @param scale a value greater than or equal to zero representing the
202      * desired number of digits to the right of the decimal point
203      * @return the parameter value; if the value is SQL NULL, the result is null
204      */

205   public BigDecimal JavaDoc getBigDecimal(int parameterIndex, int scale)
206   throws RemoteException, SQLException {
207     return jdbcCallableStmt_.getBigDecimal(parameterIndex, scale);
208   }
209
210     /**
211      * Get the value of a SQL BINARY or VARBINARY parameter as a Java byte[]
212      *
213      * @param parameterIndex the first parameter is 1, the second is 2, ...
214      * @return the parameter value; if the value is SQL NULL, the result is null
215      */

216   public byte[] getBytes(int parameterIndex) throws RemoteException, SQLException {
217     return jdbcCallableStmt_.getBytes(parameterIndex);
218   }
219
220     /**
221      * Get the value of a SQL DATE parameter as a java.sql.Date object
222      *
223      * @param parameterIndex the first parameter is 1, the second is 2, ...
224      * @return the parameter value; if the value is SQL NULL, the result is null
225      */

226   public java.sql.Date JavaDoc getDate(int parameterIndex) throws RemoteException, SQLException {
227     return jdbcCallableStmt_.getDate(parameterIndex);
228   }
229
230     /**
231      * Get the value of a SQL TIME parameter as a java.sql.Time object.
232      *
233      * @param parameterIndex the first parameter is 1, the second is 2, ...
234      * @return the parameter value; if the value is SQL NULL, the result is null
235      */

236   public java.sql.Time JavaDoc getTime(int parameterIndex) throws RemoteException, SQLException {
237     return jdbcCallableStmt_.getTime(parameterIndex);
238   }
239
240     /**
241      * Get the value of a SQL TIMESTAMP parameter as a java.sql.Timestamp object.
242      *
243      * @param parameterIndex the first parameter is 1, the second is 2, ...
244      * @return the parameter value; if the value is SQL NULL, the result is null
245      */

246   public java.sql.Timestamp JavaDoc getTimestamp(int parameterIndex)
247   throws RemoteException, SQLException {
248     return jdbcCallableStmt_.getTimestamp(parameterIndex);
249   }
250
251   //----------------------------------------------------------------------
252
// Advanced features:
253

254   /**
255    * Get the value of a parameter as a Java object.
256    *
257    * <p>This method returns a Java object whose type coresponds to the SQL
258    * type that was registered for this parameter using registerOutParameter.
259    *
260    * <p>Note that this method may be used to read
261    * datatabase-specific, abstract data types. This is done by
262    * specifying a targetSqlType of java.sql.types.OTHER, which
263    * allows the driver to return a database-specific Java type.
264    *
265    * @param parameterIndex The first parameter is 1, the second is 2, ...
266    * @return A java.lang.Object holding the OUT parameter value.
267    * @see Types
268    */

269   public Object JavaDoc getObject(int parameterIndex)
270   throws RemoteException, SQLException {
271     return jdbcCallableStmt_.getObject(parameterIndex);
272   }
273
274   //1.2 Added by Peter Hearty (peter.hearty@lutris.com) Aug 2000.
275
public void registerOutParameter(int paramIndex, int sqlType,
276   String JavaDoc typeName) throws RemoteException, SQLException {
277     jdbcCallableStmt_.registerOutParameter(paramIndex, sqlType, typeName);
278   }
279
280   public Timestamp getTimestamp(int parameterIndex, Calendar JavaDoc cal)
281   throws RemoteException, SQLException {
282     return jdbcCallableStmt_.getTimestamp(parameterIndex,cal);
283   }
284
285   public Time getTime(int parameterIndex, Calendar JavaDoc cal)
286   throws RemoteException, SQLException {
287     return jdbcCallableStmt_.getTime(parameterIndex,cal);
288   }
289
290   public RJRefInterface getRef(int i) throws RemoteException, SQLException {
291     return new RJRefServer(jdbcCallableStmt_.getRef(i));
292   }
293
294   public Object JavaDoc getObject(int i,java.util.Map JavaDoc map) throws RemoteException, SQLException {
295     return jdbcCallableStmt_.getObject(i,map);
296   }
297
298   public Date getDate(int parameterIndex, Calendar JavaDoc cal)
299   throws RemoteException, SQLException {
300     return jdbcCallableStmt_.getDate(parameterIndex,cal) ;
301   }
302
303   public RJClobInterface getClob(int i) throws RemoteException, SQLException {
304     return new RJClobServer(jdbcCallableStmt_.getClob(i));
305   }
306
307   public void setTimestamp(int parameterIndex, Timestamp x,
308   Calendar JavaDoc cal) throws RemoteException, SQLException {
309     jdbcCallableStmt_.setTimestamp(parameterIndex,x,cal);
310   }
311
312   public RJBlobInterface getBlob(int i) throws RemoteException, SQLException {
313     return new RJBlobServer(jdbcCallableStmt_.getBlob(i));
314   }
315
316   public BigDecimal JavaDoc getBigDecimal(int parameterIndex)
317   throws RemoteException, SQLException {
318     return jdbcCallableStmt_.getBigDecimal(parameterIndex);
319   }
320
321   public RJArrayInterface getArray(int i)
322   throws RemoteException, SQLException {
323     return new RJArrayServer(jdbcCallableStmt_.getArray(i));
324   }
325
326  // end of java 1.2 stuff
327

328
329   //--------------------------JDBC 3.0-----------------------------
330

331    public void registerOutParameter(String JavaDoc parameterName, int sqlType)
332    throws RemoteException, SQLException {
333         jdbcCallableStmt_.registerOutParameter(parameterName, sqlType);
334    }
335
336     public void registerOutParameter(String JavaDoc parameterName, int sqlType, int scale)
337     throws RemoteException, SQLException {
338         jdbcCallableStmt_.registerOutParameter(parameterName, sqlType, scale);
339     }
340
341     public void registerOutParameter (String JavaDoc parameterName, int sqlType, String JavaDoc typeName)
342     throws RemoteException, SQLException {
343         jdbcCallableStmt_.registerOutParameter(parameterName, sqlType, typeName);
344     }
345
346     public java.net.URL JavaDoc getURL(int parameterIndex)
347     throws RemoteException, SQLException {
348         return jdbcCallableStmt_.getURL(parameterIndex);
349     }
350
351     public void setURL(String JavaDoc parameterName, java.net.URL JavaDoc val)
352     throws RemoteException, SQLException {
353         jdbcCallableStmt_.setURL(parameterName, val);
354     }
355     
356     
357     public void setNull(String JavaDoc parameterName, int sqlType)
358     throws RemoteException, SQLException {
359         jdbcCallableStmt_.setNull(parameterName, sqlType);
360     }
361
362     public void setBoolean(String JavaDoc parameterName, boolean x)
363     throws RemoteException, SQLException {
364         jdbcCallableStmt_.setBoolean(parameterName, x);
365     }
366
367     public void setByte(String JavaDoc parameterName, byte x)
368     throws RemoteException, SQLException {
369         jdbcCallableStmt_.setByte(parameterName, x);
370     }
371     
372
373     public void setShort(String JavaDoc parameterName, short x)
374     throws RemoteException, SQLException {
375         jdbcCallableStmt_.setShort(parameterName, x);
376     }
377     
378
379     public void setInt(String JavaDoc parameterName, int x)
380     throws RemoteException, SQLException {
381         jdbcCallableStmt_.setInt(parameterName, x);
382     }
383
384
385     public void setLong(String JavaDoc parameterName, long x)
386     throws RemoteException, SQLException {
387         jdbcCallableStmt_.setLong(parameterName, x);
388     }
389
390
391     public void setFloat(String JavaDoc parameterName, float x)
392     throws RemoteException, SQLException {
393         jdbcCallableStmt_.setFloat(parameterName, x);
394     }
395     
396
397     public void setDouble(String JavaDoc parameterName, double x)
398     throws RemoteException, SQLException {
399         jdbcCallableStmt_.setDouble(parameterName, x);
400     }
401     
402
403     public void setBigDecimal(String JavaDoc parameterName, BigDecimal JavaDoc x)
404     throws RemoteException, SQLException {
405         jdbcCallableStmt_.setBigDecimal(parameterName, x);
406     }
407     
408
409     public void setString(String JavaDoc parameterName, String JavaDoc x)
410     throws RemoteException, SQLException {
411         jdbcCallableStmt_.setString(parameterName, x);
412     }
413     
414
415     public void setBytes(String JavaDoc parameterName, byte x[])
416     throws RemoteException, SQLException {
417         jdbcCallableStmt_.setBytes(parameterName, x);
418     }
419     
420
421     public void setDate(String JavaDoc parameterName, java.sql.Date JavaDoc x)
422     throws RemoteException, SQLException {
423         jdbcCallableStmt_.setDate(parameterName, x);
424     }
425
426     public void setTime(String JavaDoc parameterName, java.sql.Time JavaDoc x)
427     throws RemoteException, SQLException {
428         jdbcCallableStmt_.setTime(parameterName, x);
429     }
430
431     public void setTimestamp(String JavaDoc parameterName, java.sql.Timestamp JavaDoc x)
432     throws RemoteException, SQLException {
433         jdbcCallableStmt_.setTimestamp(parameterName, x);
434     }
435
436     public void setAsciiStream(String JavaDoc parameterName, java.io.InputStream JavaDoc x, int length)
437     throws RemoteException, SQLException {
438         jdbcCallableStmt_.setAsciiStream(parameterName, x, length);
439     }
440
441     public void setBinaryStream(String JavaDoc parameterName, java.io.InputStream JavaDoc x, int length)
442     throws RemoteException, SQLException {
443         jdbcCallableStmt_.setBinaryStream(parameterName, x, length);
444     }
445     
446
447     public void setObject(String JavaDoc parameterName, Object JavaDoc x, int targetSqlType, int scale)
448     throws RemoteException, SQLException {
449         jdbcCallableStmt_.setObject(parameterName, x, targetSqlType, scale);
450     }
451
452     public void setObject(String JavaDoc parameterName, Object JavaDoc x, int targetSqlType)
453     throws RemoteException, SQLException {
454         jdbcCallableStmt_.setObject(parameterName, x, targetSqlType);
455     }
456
457     public void setObject(String JavaDoc parameterName, Object JavaDoc x)
458     throws RemoteException, SQLException {
459         jdbcCallableStmt_.setObject(parameterName, x);
460     }
461     
462
463     public void setCharacterStream(String JavaDoc parameterName, java.io.Reader JavaDoc reader, int length)
464     throws RemoteException, SQLException {
465         jdbcCallableStmt_.setCharacterStream(parameterName, reader, length);
466     }
467
468     public void setDate(String JavaDoc parameterName, java.sql.Date JavaDoc x, Calendar JavaDoc cal)
469     throws RemoteException, SQLException {
470         jdbcCallableStmt_.setDate(parameterName, x, cal);
471     }
472
473     public void setTime(String JavaDoc parameterName, java.sql.Time JavaDoc x, Calendar JavaDoc cal)
474     throws RemoteException, SQLException {
475         jdbcCallableStmt_.setTime(parameterName, x, cal);
476     }
477
478     public void setTimestamp(String JavaDoc parameterName, java.sql.Timestamp JavaDoc x, Calendar JavaDoc cal)
479     throws RemoteException, SQLException {
480         jdbcCallableStmt_.setTimestamp(parameterName, x, cal);
481     }
482
483     public void setNull (String JavaDoc parameterName, int sqlType, String JavaDoc typeName)
484     throws RemoteException, SQLException {
485 /**TBD jdbcCallableStmt_.setNull(parameterName, sqlType, typeName); **/
486  jdbcCallableStmt_.setNull(parameterName, sqlType, typeName);
487     }
488
489     public String JavaDoc getString(String JavaDoc parameterName)
490     throws RemoteException, SQLException {
491         return jdbcCallableStmt_.getString(parameterName);
492     }
493
494     public boolean getBoolean(String JavaDoc parameterName)
495     throws RemoteException, SQLException {
496         return jdbcCallableStmt_.getBoolean(parameterName);
497     }
498
499     public byte getByte(String JavaDoc parameterName)
500     throws RemoteException, SQLException {
501         return jdbcCallableStmt_.getByte(parameterName);
502     }
503     
504     public short getShort(String JavaDoc parameterName)
505     throws RemoteException, SQLException {
506         return jdbcCallableStmt_.getShort(parameterName);
507     }
508     
509     public int getInt(String JavaDoc parameterName)
510     throws RemoteException, SQLException {
511         return jdbcCallableStmt_.getInt(parameterName);
512     }
513     
514     public long getLong(String JavaDoc parameterName)
515     throws RemoteException, SQLException {
516         return jdbcCallableStmt_.getLong(parameterName);
517     }
518     
519     public float getFloat(String JavaDoc parameterName)
520     throws RemoteException, SQLException {
521         return jdbcCallableStmt_.getFloat(parameterName);
522     }
523
524     public double getDouble(String JavaDoc parameterName)
525     throws RemoteException, SQLException {
526         return jdbcCallableStmt_.getDouble(parameterName);
527     }
528     
529     public byte[] getBytes(String JavaDoc parameterName)
530     throws RemoteException, SQLException {
531         return jdbcCallableStmt_.getBytes(parameterName);
532     }
533     
534     public java.sql.Date JavaDoc getDate(String JavaDoc parameterName)
535     throws RemoteException, SQLException {
536         return jdbcCallableStmt_.getDate(parameterName);
537     }
538
539     public java.sql.Time JavaDoc getTime(String JavaDoc parameterName)
540     throws RemoteException, SQLException {
541         return jdbcCallableStmt_.getTime(parameterName);
542     }
543     
544     public java.sql.Timestamp JavaDoc getTimestamp(String JavaDoc parameterName)
545     throws RemoteException, SQLException {
546         return jdbcCallableStmt_.getTimestamp(parameterName);
547     }
548
549     public Object JavaDoc getObject(String JavaDoc parameterName)
550     throws RemoteException, SQLException {
551         return jdbcCallableStmt_.getObject(parameterName);
552     }
553     
554     public BigDecimal JavaDoc getBigDecimal(String JavaDoc parameterName)
555     throws RemoteException, SQLException {
556         return jdbcCallableStmt_.getBigDecimal(parameterName);
557     }
558
559     public Object JavaDoc getObject (String JavaDoc parameterName, java.util.Map JavaDoc map)
560     throws RemoteException, SQLException {
561         return jdbcCallableStmt_.getObject(parameterName, map);
562     }
563     
564     public RJRefInterface getRef(String JavaDoc parameterName)
565     throws RemoteException, SQLException {
566         return new RJRefServer(jdbcCallableStmt_.getRef(parameterName));
567     }
568     
569     public RJBlobInterface getBlob (String JavaDoc parameterName)
570     throws RemoteException, SQLException {
571         return new RJBlobServer(jdbcCallableStmt_.getBlob(parameterName));
572     }
573
574     public RJClobInterface getClob (String JavaDoc parameterName)
575     throws RemoteException, SQLException {
576         return new RJClobServer(jdbcCallableStmt_.getClob(parameterName));
577     }
578     
579     public RJArrayInterface getArray (String JavaDoc parameterName)
580     throws RemoteException, SQLException {
581         return new RJArrayServer(jdbcCallableStmt_.getArray(parameterName));
582     }
583
584     public java.sql.Date JavaDoc getDate(String JavaDoc parameterName, Calendar JavaDoc cal)
585     throws RemoteException, SQLException {
586         return jdbcCallableStmt_.getDate(parameterName, cal);
587     }
588         
589     public java.sql.Time JavaDoc getTime(String JavaDoc parameterName, Calendar JavaDoc cal)
590     throws RemoteException, SQLException {
591         return jdbcCallableStmt_.getTime(parameterName, cal);
592     }
593
594     public java.sql.Timestamp JavaDoc getTimestamp(String JavaDoc parameterName, Calendar JavaDoc cal)
595     throws RemoteException, SQLException {
596         return jdbcCallableStmt_.getTimestamp(parameterName, cal);
597     }
598
599     public java.net.URL JavaDoc getURL(String JavaDoc parameterName)
600     throws RemoteException, SQLException {
601         return jdbcCallableStmt_.getURL(parameterName);
602     }
603   
604 };
605
606
Popular Tags