001/**
002 *
003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
004 *
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either 
008 * version 2.1 of the License, or (at your option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013 * Lesser General Public License for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public 
016 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
017 * 
018 **/
019package lucee.runtime.db.driver;
020
021import java.io.InputStream;
022import java.io.Reader;
023import java.lang.reflect.InvocationTargetException;
024import java.math.BigDecimal;
025import java.net.URL;
026import java.sql.Array;
027import java.sql.Blob;
028import java.sql.CallableStatement;
029import java.sql.Clob;
030import java.sql.Date;
031import java.sql.NClob;
032import java.sql.Ref;
033import java.sql.RowId;
034import java.sql.SQLException;
035import java.sql.SQLXML;
036import java.sql.Time;
037import java.sql.Timestamp;
038import java.util.Calendar;
039import java.util.Map;
040
041import lucee.commons.lang.ExceptionUtil;
042import lucee.runtime.exp.PageRuntimeException;
043import lucee.runtime.op.Caster;
044
045public class CallableStatementProxy extends PreparedStatementProxy implements CallableStatement {
046
047        protected CallableStatement stat;
048
049        public CallableStatementProxy(ConnectionProxy conn, CallableStatement prepareCall, String sql) {
050                super(conn,prepareCall,sql);
051                this.stat=prepareCall; 
052        }
053
054        @Override
055        public Array getArray(int parameterIndex) throws SQLException {
056                return stat.getArray(parameterIndex);
057        }
058
059        @Override
060        public Array getArray(String parameterName) throws SQLException {
061                return stat.getArray(parameterName);
062        }
063
064        @Override
065        public BigDecimal getBigDecimal(int parameterIndex) throws SQLException {
066                return stat.getBigDecimal(parameterIndex);
067        }
068
069        @Override
070        public BigDecimal getBigDecimal(String parameterName) throws SQLException {
071                return stat.getBigDecimal(parameterName);
072        }
073
074        @Override
075        public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException {
076                return stat.getBigDecimal(parameterIndex, scale);
077        }
078
079        @Override
080        public Blob getBlob(int parameterIndex) throws SQLException {
081                return stat.getBlob(parameterIndex);
082        }
083
084        @Override
085        public Blob getBlob(String parameterName) throws SQLException {
086                return stat.getBlob(parameterName);
087        }
088
089        @Override
090        public boolean getBoolean(int parameterIndex) throws SQLException {
091                return stat.getBoolean(parameterIndex);
092        }
093
094        @Override
095        public boolean getBoolean(String parameterName) throws SQLException {
096                return stat.getBoolean(parameterName);
097        }
098
099        @Override
100        public byte getByte(int parameterIndex) throws SQLException {
101                return stat.getByte(parameterIndex);
102        }
103
104        @Override
105        public byte getByte(String parameterName) throws SQLException {
106                return stat.getByte(parameterName);
107        }
108
109        @Override
110        public byte[] getBytes(int parameterIndex) throws SQLException {
111                return stat.getBytes(parameterIndex);
112        }
113
114        @Override
115        public byte[] getBytes(String parameterName) throws SQLException {
116                return stat.getBytes(parameterName);
117        }
118
119        @Override
120        public Reader getCharacterStream(int parameterIndex) throws SQLException {
121                return stat.getCharacterStream(parameterIndex);
122        }
123
124        @Override
125        public Reader getCharacterStream(String parameterName) throws SQLException {
126                return stat.getCharacterStream(parameterName);
127        }
128
129        @Override
130        public Clob getClob(int parameterIndex) throws SQLException {
131                return stat.getClob(parameterIndex);
132        }
133
134        @Override
135        public Clob getClob(String parameterName) throws SQLException {
136                return stat.getClob(parameterName);
137        }
138
139        @Override
140        public Date getDate(int parameterIndex) throws SQLException {
141                return stat.getDate(parameterIndex);
142        }
143
144        @Override
145        public Date getDate(String parameterName) throws SQLException {
146                return stat.getDate(parameterName);
147        }
148
149        @Override
150        public Date getDate(int parameterIndex, Calendar cal) throws SQLException {
151                return stat.getDate(parameterIndex, cal);
152        }
153
154        @Override
155        public Date getDate(String parameterName, Calendar cal) throws SQLException {
156                return stat.getDate(parameterName, cal);
157        }
158
159        @Override
160        public double getDouble(int parameterIndex) throws SQLException {
161                return stat.getDouble(parameterIndex);
162        }
163
164        @Override
165        public double getDouble(String parameterName) throws SQLException {
166                return stat.getDouble(parameterName);
167        }
168
169        @Override
170        public float getFloat(int parameterIndex) throws SQLException {
171                return stat.getFloat(parameterIndex);
172        }
173
174        @Override
175        public float getFloat(String parameterName) throws SQLException {
176                return stat.getFloat(parameterName);
177        }
178
179        @Override
180        public int getInt(int parameterIndex) throws SQLException {
181                return stat.getInt(parameterIndex);
182        }
183
184        @Override
185        public int getInt(String parameterName) throws SQLException {
186                return stat.getInt(parameterName);
187        }
188
189        @Override
190        public long getLong(int parameterIndex) throws SQLException {
191                return stat.getLong(parameterIndex);
192        }
193
194        @Override
195        public long getLong(String parameterName) throws SQLException {
196                return stat.getLong(parameterName);
197        }
198
199        @Override
200        public Reader getNCharacterStream(int parameterIndex) throws SQLException {
201                return stat.getNCharacterStream(parameterIndex);
202        }
203
204        @Override
205        public Reader getNCharacterStream(String parameterName) throws SQLException {
206                return stat.getNCharacterStream(parameterName);
207        }
208
209        @Override
210        public NClob getNClob(int parameterIndex) throws SQLException {
211                return stat.getNClob(parameterIndex);
212        }
213
214        @Override
215        public NClob getNClob(String parameterName) throws SQLException {
216                return stat.getNClob(parameterName);
217        }
218
219        @Override
220        public String getNString(int parameterIndex) throws SQLException {
221                return stat.getNString(parameterIndex);
222        }
223
224        @Override
225        public String getNString(String parameterName) throws SQLException {
226                return stat.getNString(parameterName);
227        }
228
229        @Override
230        public Object getObject(int parameterIndex) throws SQLException {
231                return stat.getObject(parameterIndex);
232        }
233
234        @Override
235        public Object getObject(String parameterName) throws SQLException {
236                return stat.getObject(parameterName);
237        }
238
239        @Override
240        public Object getObject(int parameterIndex, Map<String, Class<?>> map) throws SQLException {
241                return stat.getObject(parameterIndex, map);
242        }
243
244        @Override
245        public Object getObject(String parameterName, Map<String, Class<?>> map) throws SQLException {
246                return stat.getObject(parameterName, map);
247        }
248
249        @Override
250        public Ref getRef(int parameterIndex) throws SQLException {
251                return stat.getRef(parameterIndex);
252        }
253
254        @Override
255        public Ref getRef(String parameterName) throws SQLException {
256                return stat.getRef(parameterName);
257        }
258
259        @Override
260        public RowId getRowId(int parameterIndex) throws SQLException {
261                return stat.getRowId(parameterIndex);
262        }
263
264        @Override
265        public RowId getRowId(String parameterName) throws SQLException {
266                return stat.getRowId(parameterName);
267        }
268
269        @Override
270        public SQLXML getSQLXML(int parameterIndex) throws SQLException {
271                return stat.getSQLXML(parameterIndex);
272        }
273
274        @Override
275        public SQLXML getSQLXML(String parameterName) throws SQLException {
276                return stat.getSQLXML(parameterName);
277        }
278
279        @Override
280        public short getShort(int parameterIndex) throws SQLException {
281                return stat.getShort(parameterIndex);
282        }
283
284        @Override
285        public short getShort(String parameterName) throws SQLException {
286                return stat.getShort(parameterName);
287        }
288
289        @Override
290        public String getString(int parameterIndex) throws SQLException {
291                return stat.getString(parameterIndex);
292        }
293
294        @Override
295        public String getString(String parameterName) throws SQLException {
296                return stat.getString(parameterName);
297        }
298
299        @Override
300        public Time getTime(int parameterIndex) throws SQLException {
301                return stat.getTime(parameterIndex);
302        }
303
304        @Override
305        public Time getTime(String parameterName) throws SQLException {
306                return stat.getTime(parameterName);
307        }
308
309        @Override
310        public Time getTime(int parameterIndex, Calendar cal) throws SQLException {
311                return stat.getTime(parameterIndex, cal);
312        }
313
314        @Override
315        public Time getTime(String parameterName, Calendar cal) throws SQLException {
316                return stat.getTime(parameterName, cal);
317        }
318
319        @Override
320        public Timestamp getTimestamp(int parameterIndex) throws SQLException {
321                return stat.getTimestamp(parameterIndex);
322        }
323
324        @Override
325        public Timestamp getTimestamp(String parameterName) throws SQLException {
326                return stat.getTimestamp(parameterName);
327        }
328
329        @Override
330        public Timestamp getTimestamp(int parameterIndex, Calendar cal) throws SQLException {
331                return stat.getTimestamp(parameterIndex, cal);
332        }
333
334        @Override
335        public Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException {
336                return stat.getTimestamp(parameterName, cal);
337        }
338
339        @Override
340        public URL getURL(int parameterIndex) throws SQLException {
341                return stat.getURL(parameterIndex);
342        }
343
344        @Override
345        public URL getURL(String parameterName) throws SQLException {
346                return stat.getURL(parameterName);
347        }
348
349        @Override
350        public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException {
351                stat.registerOutParameter(parameterIndex, sqlType);
352        }
353
354        @Override
355        public void registerOutParameter(String parameterName, int sqlType) throws SQLException {
356                stat.registerOutParameter(parameterName, sqlType);
357        }
358
359        @Override
360        public void registerOutParameter(int parameterIndex, int sqlType, int typeName) throws SQLException {
361                stat.registerOutParameter(parameterIndex, sqlType, typeName);
362        }
363
364        @Override
365        public void registerOutParameter(int parameterIndex, int sqlType, String typeName) throws SQLException {
366                stat.registerOutParameter(parameterIndex, sqlType, typeName);
367        }
368
369        @Override
370        public void registerOutParameter(String parameterName, int sqlType, int scale) throws SQLException {
371                stat.registerOutParameter(parameterName, sqlType, scale);
372        }
373
374        @Override
375        public void registerOutParameter(String parameterName, int sqlType, String typeName) throws SQLException {
376                stat.registerOutParameter(parameterName, sqlType, typeName);
377        }
378
379        @Override
380        public void setAsciiStream(String parameterName, InputStream x) throws SQLException {
381                stat.setAsciiStream(parameterName, x);
382        }
383
384        @Override
385        public void setAsciiStream(String parameterName, InputStream x, int length)throws SQLException {
386                stat.setAsciiStream(parameterName, x, length);
387        }
388
389        @Override
390        public void setAsciiStream(String parameterName, InputStream x, long length) throws SQLException {
391                stat.setAsciiStream(parameterName, x, length);
392        }
393
394        @Override
395        public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException {
396                stat.setBigDecimal(parameterName, x);
397        }
398
399        @Override
400        public void setBinaryStream(String parameterName, InputStream x) throws SQLException {
401                stat.setBinaryStream(parameterName, x);
402        }
403
404        @Override
405        public void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException {
406                stat.setBinaryStream(parameterName, x, length);
407        }
408
409        @Override
410        public void setBinaryStream(String parameterName, InputStream x, long length) throws SQLException {
411                stat.setBinaryStream(parameterName, x, length);
412        }
413
414        @Override
415        public void setBlob(String parameterName, Blob x) throws SQLException {
416                stat.setBlob(parameterName, x);
417        }
418
419        @Override
420        public void setBlob(String parameterName, InputStream inputStream) throws SQLException {
421                stat.setBlob(parameterName, inputStream);
422        }
423
424        @Override
425        public void setBlob(String parameterName, InputStream is, long length) throws SQLException {
426                stat.setBlob(parameterName, is, length);
427        }
428
429        @Override
430        public void setBoolean(String parameterName, boolean x) throws SQLException {
431                stat.setBoolean(parameterName, x);
432        }
433
434        @Override
435        public void setByte(String parameterName, byte x) throws SQLException {
436                stat.setByte(parameterName, x);
437        }
438
439        @Override
440        public void setBytes(String parameterName, byte[] x) throws SQLException {
441                stat.setBytes(parameterName, x);
442        }
443
444        @Override
445        public void setCharacterStream(String parameterName, Reader reader)
446                        throws SQLException {
447                stat.setCharacterStream(parameterName, reader);
448        }
449
450        @Override
451        public void setCharacterStream(String parameterName, Reader reader, int length)
452                        throws SQLException {
453                stat.setCharacterStream(parameterName, reader, length);
454        }
455
456        @Override
457        public void setCharacterStream(String parameterName, Reader reader, long length)
458                        throws SQLException {
459                stat.setCharacterStream(parameterName, reader, length);
460        }
461
462        @Override
463        public void setClob(String parameterName, Clob x) throws SQLException {
464                stat.setClob(parameterName, x);
465        }
466
467        @Override
468        public void setClob(String parameterName, Reader reader) throws SQLException {
469                stat.setClob(parameterName, reader);
470        }
471
472        @Override
473        public void setClob(String parameterName, Reader reader, long length)
474                        throws SQLException {
475                stat.setClob(parameterName, reader, length);
476        }
477
478        @Override
479        public void setDate(String parameterName, Date x) throws SQLException {
480                stat.setDate(parameterName, x);
481        }
482
483        @Override
484        public void setDate(String parameterName, Date x, Calendar cal)
485                        throws SQLException {
486                stat.setDate(parameterName, x, cal);
487        }
488
489        @Override
490        public void setDouble(String parameterName, double x) throws SQLException {
491                stat.setDouble(parameterName, x);
492        }
493
494        @Override
495        public void setFloat(String parameterName, float x) throws SQLException {
496                stat.setFloat(parameterName, x);
497        }
498
499        @Override
500        public void setInt(String parameterName, int x) throws SQLException {
501                stat.setInt(parameterName, x);
502        }
503
504        @Override
505        public void setLong(String parameterName, long x) throws SQLException {
506                stat.setLong(parameterName, x);
507        }
508
509        @Override
510        public void setNCharacterStream(String parameterName, Reader value)
511                        throws SQLException {
512                stat.setNCharacterStream(parameterName, value);
513        }
514
515        @Override
516        public void setNCharacterStream(String parameterName, Reader value, long length)
517                        throws SQLException {
518                stat.setNCharacterStream(parameterName, value, length);
519        }
520
521        @Override
522        public void setNClob(String parameterName, NClob value) throws SQLException {
523                stat.setNClob(parameterName, value);
524        }
525
526        @Override
527        public void setNClob(String parameterName, Reader reader) throws SQLException {
528                stat.setNClob(parameterName, reader);
529        }
530
531        @Override
532        public void setNClob(String parameterName, Reader reader, long length)
533                        throws SQLException {
534                stat.setNClob(parameterName, reader, length);
535        }
536
537        @Override
538        public void setNString(String parameterName, String value) throws SQLException {
539                stat.setNString(parameterName, value);
540        }
541
542        @Override
543        public void setNull(String parameterName, int sqlType) throws SQLException {
544                stat.setNull(parameterName, sqlType);
545        }
546
547        @Override
548        public void setNull(String parameterName, int sqlType, String typeName) throws SQLException {
549                stat.setNull(parameterName, sqlType, typeName);
550        }
551
552        @Override
553        public void setObject(String parameterName, Object x) throws SQLException {
554                stat.setObject(parameterName, x);
555        }
556
557        @Override
558        public void setObject(String parameterName, Object x, int targetSqlType)
559                        throws SQLException {
560                stat.setObject(parameterName, x, targetSqlType);
561        }
562
563        @Override
564        public void setObject(String parameterName, Object x, int targetSqlType, int scale)
565                        throws SQLException {
566                stat.setObject(parameterName, x, targetSqlType, scale);
567        }
568
569        @Override
570        public void setRowId(String parameterName, RowId x) throws SQLException {
571                stat.setRowId(parameterName, x);
572        }
573
574        @Override
575        public void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException {
576                stat.setSQLXML(parameterName, xmlObject);
577        }
578
579        @Override
580        public void setShort(String parameterName, short x) throws SQLException {
581                stat.setShort(parameterName, x);
582        }
583
584        @Override
585        public void setString(String parameterName, String x) throws SQLException {
586                stat.setString(parameterName, x);
587        }
588
589        @Override
590        public void setTime(String parameterName, Time x) throws SQLException {
591                stat.setTime(parameterName, x);
592        }
593
594        @Override
595        public void setTime(String parameterName, Time x, Calendar cal)
596                        throws SQLException {
597                stat.setTime(parameterName, x, cal);
598        }
599
600        @Override
601        public void setTimestamp(String parameterName, Timestamp x) throws SQLException {
602                stat.setTimestamp(parameterName, x);
603        }
604
605        @Override
606        public void setTimestamp(String parameterName, Timestamp x, Calendar cal)
607                        throws SQLException {
608                stat.setTimestamp(parameterName, x, cal);
609        }
610
611        @Override
612        public void setURL(String parameterName, URL val) throws SQLException {
613                stat.setURL(parameterName, val);
614        }
615
616        @Override
617        public boolean wasNull() throws SQLException {
618                return stat.wasNull();
619        }
620
621        public <T> T getObject(int parameterIndex, Class<T> type) throws SQLException {
622                // used reflection to make sure this work with Java 5 and 6
623                try {
624                        return (T) stat.getClass().getMethod("getObject", new Class[]{int.class,Class.class}).invoke(stat, new Object[]{parameterIndex,type});
625                }
626                catch (Throwable t) {
627                ExceptionUtil.rethrowIfNecessary(t);
628                        if(t instanceof InvocationTargetException && ((InvocationTargetException)t).getTargetException() instanceof SQLException)
629                                throw (SQLException)((InvocationTargetException)t).getTargetException();
630                        throw new PageRuntimeException(Caster.toPageException(t));
631                }
632        }
633
634        public <T> T getObject(String parameterName, Class<T> type) throws SQLException {
635                // used reflection to make sure this work with Java 5 and 6
636                try {
637                        return (T) stat.getClass().getMethod("getObject", new Class[]{String.class,Class.class}).invoke(stat, new Object[]{parameterName,type});
638                }
639                catch (Throwable t) {
640                ExceptionUtil.rethrowIfNecessary(t);
641                        if(t instanceof InvocationTargetException && ((InvocationTargetException)t).getTargetException() instanceof SQLException)
642                                throw (SQLException)((InvocationTargetException)t).getTargetException();
643                        throw new PageRuntimeException(Caster.toPageException(t));
644                }
645        }
646}