1 | /* ============================================================= |
2 | * SmallSQL : a free Java DBMS library for the Java(tm) platform |
3 | * ============================================================= |
4 | * |
5 | * (C) Copyright 2004-2006, by Volker Berlin. |
6 | * |
7 | * Project Info: http://www.smallsql.de/ |
8 | * |
9 | * This library is free software; you can redistribute it and/or modify it |
10 | * under the terms of the GNU Lesser General Public License as published by |
11 | * the Free Software Foundation; either version 2.1 of the License, or |
12 | * (at your option) any later version. |
13 | * |
14 | * This library is distributed in the hope that it will be useful, but |
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
16 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
17 | * License for more details. |
18 | * |
19 | * You should have received a copy of the GNU Lesser General Public |
20 | * License along with this library; if not, write to the Free Software |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
22 | * USA. |
23 | * |
24 | * [Java is a trademark or registered trademark of Sun Microsystems, Inc. |
25 | * in the United States and other countries.] |
26 | * |
27 | * --------------- |
28 | * SSCallableStatament.java |
29 | * --------------- |
30 | * Author: Volker Berlin |
31 | * |
32 | */ |
33 | package smallsql.database; |
34 | |
35 | import java.sql.*; |
36 | import java.math.*; |
37 | import java.util.Map; |
38 | import java.util.Calendar; |
39 | import java.net.URL; |
40 | import java.io.*; |
41 | |
42 | |
43 | public class SSCallableStatement extends SSPreparedStatement implements CallableStatement { |
44 | |
45 | private boolean wasNull; |
46 | |
47 | SSCallableStatement( SSConnection con, String sql ) throws SQLException { |
48 | super( con, sql ); |
49 | } |
50 | |
51 | SSCallableStatement( SSConnection con, String sql, int rsType, int rsConcurrency ) throws SQLException { |
52 | super( con, sql, rsType, rsConcurrency ); |
53 | } |
54 | |
55 | private Expression getValue(int i) throws SQLException{ |
56 | /**@todo: Implement this java.sql.CallableStatement method*/ |
57 | throw new java.lang.UnsupportedOperationException("Method getValue() not yet implemented."); |
58 | } |
59 | |
60 | private int findParameter( String parameterName ){ |
61 | /**@todo: Implement this java.sql.CallableStatement method*/ |
62 | throw new java.lang.UnsupportedOperationException("Method findParameter() not yet implemented."); |
63 | } |
64 | /*============================================================================== |
65 | |
66 | Public Interface |
67 | |
68 | ==============================================================================*/ |
69 | public void registerOutParameter(int i, int sqlType) throws SQLException { |
70 | /**@todo: Implement this java.sql.CallableStatement method*/ |
71 | throw new java.lang.UnsupportedOperationException("Method registerOutParameter() not yet implemented."); |
72 | } |
73 | public void registerOutParameter(int i, int sqlType, int scale) throws SQLException { |
74 | /**@todo: Implement this java.sql.CallableStatement method*/ |
75 | throw new java.lang.UnsupportedOperationException("Method registerOutParameter() not yet implemented."); |
76 | } |
77 | public boolean wasNull() throws SQLException { |
78 | return wasNull; |
79 | } |
80 | public String getString(int i) throws SQLException { |
81 | try{ |
82 | String obj = getValue(i).getString(); |
83 | wasNull = obj == null; |
84 | return obj; |
85 | }catch(Exception e){ |
86 | throw Utils.createSQLException( e ); |
87 | } |
88 | } |
89 | public boolean getBoolean(int i) throws SQLException { |
90 | try{ |
91 | Expression expr = getValue(i); |
92 | wasNull = expr.isNull(); |
93 | return expr.getBoolean(); |
94 | }catch(Exception e){ |
95 | throw Utils.createSQLException( e ); |
96 | } |
97 | } |
98 | public byte getByte(int i) throws SQLException { |
99 | return (byte)getInt( i ); |
100 | } |
101 | public short getShort(int i) throws SQLException { |
102 | return (byte)getInt( i ); |
103 | } |
104 | public int getInt(int i) throws SQLException { |
105 | try{ |
106 | Expression expr = getValue(i); |
107 | wasNull = expr.isNull(); |
108 | return expr.getInt(); |
109 | }catch(Exception e){ |
110 | throw Utils.createSQLException( e ); |
111 | } |
112 | } |
113 | public long getLong(int i) throws SQLException { |
114 | try{ |
115 | Expression expr = getValue(i); |
116 | wasNull = expr.isNull(); |
117 | return expr.getLong(); |
118 | }catch(Exception e){ |
119 | throw Utils.createSQLException( e ); |
120 | } |
121 | } |
122 | public float getFloat(int i) throws SQLException { |
123 | try{ |
124 | Expression expr = getValue(i); |
125 | wasNull = expr.isNull(); |
126 | return expr.getFloat(); |
127 | }catch(Exception e){ |
128 | throw Utils.createSQLException( e ); |
129 | } |
130 | } |
131 | public double getDouble(int i) throws SQLException { |
132 | try{ |
133 | Expression expr = getValue(i); |
134 | wasNull = expr.isNull(); |
135 | return expr.getLong(); |
136 | }catch(Exception e){ |
137 | throw Utils.createSQLException( e ); |
138 | } |
139 | } |
140 | public BigDecimal getBigDecimal(int i, int scale) throws SQLException { |
141 | try{ |
142 | MutableNumeric obj = getValue(i).getNumeric(); |
143 | if(wasNull = obj == null) return null; |
144 | return obj.toBigDecimal(scale); |
145 | }catch(Exception e){ |
146 | throw Utils.createSQLException( e ); |
147 | } |
148 | } |
149 | public byte[] getBytes(int i) throws SQLException { |
150 | try{ |
151 | byte[] obj = getValue(i).getBytes(); |
152 | wasNull = obj == null; |
153 | return obj; |
154 | }catch(Exception e){ |
155 | throw Utils.createSQLException( e ); |
156 | } |
157 | } |
158 | public Date getDate(int i) throws SQLException { |
159 | try{ |
160 | Expression expr = getValue(i); |
161 | if(wasNull = expr.isNull()) return null; |
162 | return DateTime.getDate( expr.getLong() ); |
163 | }catch(Exception e){ |
164 | throw Utils.createSQLException( e ); |
165 | } |
166 | } |
167 | public Time getTime(int i) throws SQLException { |
168 | try{ |
169 | Expression expr = getValue(i); |
170 | if(wasNull = expr.isNull()) return null; |
171 | return DateTime.getTime( expr.getLong() ); |
172 | }catch(Exception e){ |
173 | throw Utils.createSQLException( e ); |
174 | } |
175 | } |
176 | public Timestamp getTimestamp(int i) throws SQLException { |
177 | try{ |
178 | Expression expr = getValue(i); |
179 | if(wasNull = expr.isNull()) return null; |
180 | return DateTime.getTimestamp( expr.getLong() ); |
181 | }catch(Exception e){ |
182 | throw Utils.createSQLException( e ); |
183 | } |
184 | } |
185 | public Object getObject(int i) throws SQLException { |
186 | try{ |
187 | Object obj = getValue(i).getObject(); |
188 | wasNull = obj == null; |
189 | return obj; |
190 | }catch(Exception e){ |
191 | throw Utils.createSQLException( e ); |
192 | } |
193 | } |
194 | public BigDecimal getBigDecimal(int i) throws SQLException { |
195 | try{ |
196 | MutableNumeric obj = getValue(i).getNumeric(); |
197 | if(wasNull = obj == null) return null; |
198 | return obj.toBigDecimal(); |
199 | }catch(Exception e){ |
200 | throw Utils.createSQLException( e ); |
201 | } |
202 | } |
203 | public Object getObject(int i, Map map) throws SQLException { |
204 | /**@todo: Implement this java.sql.CallableStatement method*/ |
205 | throw new java.lang.UnsupportedOperationException("Method getObject() not yet implemented."); |
206 | } |
207 | public Ref getRef(int i) throws SQLException { |
208 | /**@todo: Implement this java.sql.CallableStatement method*/ |
209 | throw new java.lang.UnsupportedOperationException("Method getRef() not yet implemented."); |
210 | } |
211 | public Blob getBlob(int i) throws SQLException { |
212 | /**@todo: Implement this java.sql.CallableStatement method*/ |
213 | throw new java.lang.UnsupportedOperationException("Method getBlob() not yet implemented."); |
214 | } |
215 | public Clob getClob(int i) throws SQLException { |
216 | /**@todo: Implement this java.sql.CallableStatement method*/ |
217 | throw new java.lang.UnsupportedOperationException("Method getClob() not yet implemented."); |
218 | } |
219 | public Array getArray(int i) throws SQLException { |
220 | /**@todo: Implement this java.sql.CallableStatement method*/ |
221 | throw new java.lang.UnsupportedOperationException("Method getArray() not yet implemented."); |
222 | } |
223 | public Date getDate(int i, Calendar cal) throws SQLException { |
224 | /**@todo: Implement this java.sql.CallableStatement method*/ |
225 | throw new java.lang.UnsupportedOperationException("Method getDate() not yet implemented."); |
226 | } |
227 | public Time getTime(int i, Calendar cal) throws SQLException { |
228 | /**@todo: Implement this java.sql.CallableStatement method*/ |
229 | throw new java.lang.UnsupportedOperationException("Method getTime() not yet implemented."); |
230 | } |
231 | public Timestamp getTimestamp(int i, Calendar cal) throws SQLException { |
232 | /**@todo: Implement this java.sql.CallableStatement method*/ |
233 | throw new java.lang.UnsupportedOperationException("Method getTimestamp() not yet implemented."); |
234 | } |
235 | public void registerOutParameter(int i, int sqlType, String typeName) throws SQLException { |
236 | /**@todo: Implement this java.sql.CallableStatement method*/ |
237 | throw new java.lang.UnsupportedOperationException("Method registerOutParameter() not yet implemented."); |
238 | } |
239 | public void registerOutParameter(String parameterName, int sqlType) throws SQLException { |
240 | registerOutParameter( findParameter( parameterName ), sqlType ); |
241 | } |
242 | public void registerOutParameter(String parameterName, int sqlType, int scale) throws SQLException { |
243 | registerOutParameter( findParameter( parameterName ), sqlType, scale ); |
244 | } |
245 | public void registerOutParameter(String parameterName, int sqlType, String typeName) throws SQLException { |
246 | registerOutParameter( findParameter( parameterName ), sqlType, typeName ); |
247 | } |
248 | public URL getURL(int parameterIndex) throws SQLException { |
249 | /**@todo: Implement this java.sql.CallableStatement method*/ |
250 | throw new java.lang.UnsupportedOperationException("Method getURL() not yet implemented."); |
251 | } |
252 | public void setURL(String parameterName, URL x) throws SQLException { |
253 | setURL( findParameter( parameterName ), x ); |
254 | } |
255 | public void setNull(String parameterName, int sqlType) throws SQLException { |
256 | setNull( findParameter( parameterName ), sqlType ); |
257 | } |
258 | public void setBoolean(String parameterName, boolean x) throws SQLException { |
259 | setBoolean( findParameter( parameterName ), x ); |
260 | } |
261 | public void setByte(String parameterName, byte x) throws SQLException { |
262 | setByte( findParameter( parameterName ), x ); |
263 | } |
264 | public void setShort(String parameterName, short x) throws SQLException { |
265 | setShort( findParameter( parameterName ), x ); |
266 | } |
267 | public void setInt(String parameterName, int x) throws SQLException { |
268 | setInt( findParameter( parameterName ), x ); |
269 | } |
270 | public void setLong(String parameterName, long x) throws SQLException { |
271 | setLong( findParameter( parameterName ), x ); |
272 | } |
273 | public void setFloat(String parameterName, float x) throws SQLException { |
274 | setFloat( findParameter( parameterName ), x ); |
275 | } |
276 | public void setDouble(String parameterName, double x) throws SQLException { |
277 | setDouble( findParameter( parameterName ), x ); |
278 | } |
279 | public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException { |
280 | setBigDecimal( findParameter( parameterName ), x ); |
281 | } |
282 | public void setString(String parameterName, String x) throws SQLException { |
283 | setString( findParameter( parameterName ), x ); |
284 | } |
285 | public void setBytes(String parameterName, byte[] x) throws SQLException { |
286 | setBytes( findParameter( parameterName ), x ); |
287 | } |
288 | public void setDate(String parameterName, Date x) throws SQLException { |
289 | setDate( findParameter( parameterName ), x ); |
290 | } |
291 | public void setTime(String parameterName, Time x) throws SQLException { |
292 | setTime( findParameter( parameterName ), x ); |
293 | } |
294 | public void setTimestamp(String parameterName, Timestamp x) throws SQLException { |
295 | setTimestamp( findParameter( parameterName ), x ); |
296 | } |
297 | public void setAsciiStream(String parameterName, InputStream x, int length) throws SQLException { |
298 | setAsciiStream( findParameter( parameterName ), x, length ); |
299 | } |
300 | public void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException { |
301 | setBinaryStream( findParameter( parameterName ), x, length ); |
302 | } |
303 | public void setObject(String parameterName, Object x, int sqlType, int scale) throws SQLException { |
304 | setObject( findParameter( parameterName ), x, sqlType, scale ); |
305 | } |
306 | public void setObject(String parameterName, Object x, int sqlType) throws SQLException { |
307 | setObject( findParameter( parameterName ), x, sqlType ); |
308 | } |
309 | public void setObject(String parameterName, Object x) throws SQLException { |
310 | setObject( findParameter( parameterName ), x ); |
311 | } |
312 | public void setCharacterStream(String parameterName, Reader x, int length) throws SQLException { |
313 | setCharacterStream( findParameter( parameterName ), x, length ); |
314 | } |
315 | public void setDate(String parameterName, Date x, Calendar cal) throws SQLException { |
316 | setDate( findParameter( parameterName ), x, cal ); |
317 | } |
318 | public void setTime(String parameterName, Time x, Calendar cal) throws SQLException { |
319 | setTime( findParameter( parameterName ), x, cal ); |
320 | } |
321 | public void setTimestamp(String parameterName, Timestamp x, Calendar cal) throws SQLException { |
322 | setTimestamp( findParameter( parameterName ), x, cal ); |
323 | } |
324 | public void setNull(String parameterName, int sqlType, String typeName) throws SQLException { |
325 | setNull( findParameter( parameterName ), sqlType, typeName ); |
326 | } |
327 | public String getString(String parameterName) throws SQLException { |
328 | return getString( findParameter( parameterName ) ); |
329 | } |
330 | public boolean getBoolean(String parameterName) throws SQLException { |
331 | return getBoolean( findParameter( parameterName ) ); |
332 | } |
333 | public byte getByte(String parameterName) throws SQLException { |
334 | return getByte( findParameter( parameterName ) ); |
335 | } |
336 | public short getShort(String parameterName) throws SQLException { |
337 | return getShort( findParameter( parameterName ) ); |
338 | } |
339 | public int getInt(String parameterName) throws SQLException { |
340 | return getInt( findParameter( parameterName ) ); |
341 | } |
342 | public long getLong(String parameterName) throws SQLException { |
343 | return getLong( findParameter( parameterName ) ); |
344 | } |
345 | public float getFloat(String parameterName) throws SQLException { |
346 | return getFloat( findParameter( parameterName ) ); |
347 | } |
348 | public double getDouble(String parameterName) throws SQLException { |
349 | return getDouble( findParameter( parameterName ) ); |
350 | } |
351 | public byte[] getBytes(String parameterName) throws SQLException { |
352 | return getBytes( findParameter( parameterName ) ); |
353 | } |
354 | public Date getDate(String parameterName) throws SQLException { |
355 | return getDate( findParameter( parameterName ) ); |
356 | } |
357 | public Time getTime(String parameterName) throws SQLException { |
358 | return getTime( findParameter( parameterName ) ); |
359 | } |
360 | public Timestamp getTimestamp(String parameterName) throws SQLException { |
361 | return getTimestamp( findParameter( parameterName ) ); |
362 | } |
363 | public Object getObject(String parameterName) throws SQLException { |
364 | return getObject( findParameter( parameterName ) ); |
365 | } |
366 | public BigDecimal getBigDecimal(String parameterName) throws SQLException { |
367 | return getBigDecimal( findParameter( parameterName ) ); |
368 | } |
369 | public Object getObject(String parameterName, Map map) throws SQLException { |
370 | return getObject( findParameter( parameterName ), map ); |
371 | } |
372 | public Ref getRef(String parameterName) throws SQLException { |
373 | return getRef( findParameter( parameterName ) ); |
374 | } |
375 | public Blob getBlob(String parameterName) throws SQLException { |
376 | return getBlob( findParameter( parameterName ) ); |
377 | } |
378 | public Clob getClob(String parameterName) throws SQLException { |
379 | return getClob( findParameter( parameterName ) ); |
380 | } |
381 | public Array getArray(String parameterName) throws SQLException { |
382 | return getArray( findParameter( parameterName ) ); |
383 | } |
384 | public Date getDate(String parameterName, Calendar cal) throws SQLException { |
385 | return getDate( findParameter( parameterName ), cal ); |
386 | } |
387 | public Time getTime(String parameterName, Calendar cal) throws SQLException { |
388 | return getTime( findParameter( parameterName ), cal ); |
389 | } |
390 | public Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException { |
391 | return getTimestamp( findParameter( parameterName ), cal ); |
392 | } |
393 | public URL getURL(String parameterName) throws SQLException { |
394 | return getURL( findParameter( parameterName ) ); |
395 | } |
396 | } |