1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.apache.commons.dbcp;
  17. import java.net.URL;
  18. import java.sql.CallableStatement;
  19. import java.math.BigDecimal;
  20. import java.sql.Date;
  21. import java.sql.Time;
  22. import java.sql.Timestamp;
  23. import java.util.Map;
  24. import java.sql.Ref;
  25. import java.sql.Blob;
  26. import java.sql.Clob;
  27. import java.sql.Array;
  28. import java.util.Calendar;
  29. import java.io.InputStream;
  30. import java.io.Reader;
  31. import java.sql.SQLException;
  32. /**
  33. * A base delegating implementation of {@link CallableStatement}.
  34. * <p>
  35. * All of the methods from the {@link CallableStatement} interface
  36. * simply call the corresponding method on the "delegate"
  37. * provided in my constructor.
  38. * <p>
  39. * Extends AbandonedTrace to implement Statement tracking and
  40. * logging of code which created the Statement. Tracking the
  41. * Statement ensures that the Connection which created it can
  42. * close any open Statement's on Connection close.
  43. *
  44. * @author Glenn L. Nielsen
  45. * @author James House
  46. * @author Dirk Verbeeck
  47. * @version $Revision: 1.19 $ $Date: 2004/03/06 13:35:31 $
  48. */
  49. public class DelegatingCallableStatement extends DelegatingPreparedStatement
  50. implements CallableStatement {
  51. /** My delegate. */
  52. protected CallableStatement _stmt = null;
  53. /**
  54. * Create a wrapper for the Statement which traces this
  55. * Statement to the Connection which created it and the
  56. * code which created it.
  57. *
  58. * @param cs the {@link CallableStatement} to delegate all calls to.
  59. */
  60. public DelegatingCallableStatement(DelegatingConnection c,
  61. CallableStatement s) {
  62. super(c, s);
  63. _stmt = s;
  64. }
  65. public boolean equals(Object obj) {
  66. CallableStatement delegate = (CallableStatement) getInnermostDelegate();
  67. if (delegate == null) {
  68. return false;
  69. }
  70. if (obj instanceof DelegatingCallableStatement) {
  71. DelegatingCallableStatement s = (DelegatingCallableStatement) obj;
  72. return delegate.equals(s.getInnermostDelegate());
  73. }
  74. else {
  75. return delegate.equals(obj);
  76. }
  77. }
  78. /** Sets my delegate. */
  79. public void setDelegate(CallableStatement s) {
  80. super.setDelegate(s);
  81. _stmt = s;
  82. }
  83. public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException
  84. { checkOpen(); try { _stmt.registerOutParameter( parameterIndex, sqlType); } catch (SQLException e) { handleException(e); } }
  85. public void registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException
  86. { checkOpen(); try { _stmt.registerOutParameter( parameterIndex, sqlType, scale); } catch (SQLException e) { handleException(e); } }
  87. public boolean wasNull() throws SQLException
  88. { checkOpen(); try { return _stmt.wasNull(); } catch (SQLException e) { handleException(e); return false; } }
  89. public String getString(int parameterIndex) throws SQLException
  90. { checkOpen(); try { return _stmt.getString( parameterIndex); } catch (SQLException e) { handleException(e); return null; } }
  91. public boolean getBoolean(int parameterIndex) throws SQLException
  92. { checkOpen(); try { return _stmt.getBoolean( parameterIndex); } catch (SQLException e) { handleException(e); return false; } }
  93. public byte getByte(int parameterIndex) throws SQLException
  94. { checkOpen(); try { return _stmt.getByte( parameterIndex); } catch (SQLException e) { handleException(e); return 0; } }
  95. public short getShort(int parameterIndex) throws SQLException
  96. { checkOpen(); try { return _stmt.getShort( parameterIndex); } catch (SQLException e) { handleException(e); return 0; } }
  97. public int getInt(int parameterIndex) throws SQLException
  98. { checkOpen(); try { return _stmt.getInt( parameterIndex); } catch (SQLException e) { handleException(e); return 0; } }
  99. public long getLong(int parameterIndex) throws SQLException
  100. { checkOpen(); try { return _stmt.getLong( parameterIndex); } catch (SQLException e) { handleException(e); return 0; } }
  101. public float getFloat(int parameterIndex) throws SQLException
  102. { checkOpen(); try { return _stmt.getFloat( parameterIndex); } catch (SQLException e) { handleException(e); return 0; } }
  103. public double getDouble(int parameterIndex) throws SQLException
  104. { checkOpen(); try { return _stmt.getDouble( parameterIndex); } catch (SQLException e) { handleException(e); return 0; } }
  105. /** @deprecated */
  106. public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException
  107. { checkOpen(); try { return _stmt.getBigDecimal( parameterIndex, scale); } catch (SQLException e) { handleException(e); return null; } }
  108. public byte[] getBytes(int parameterIndex) throws SQLException
  109. { checkOpen(); try { return _stmt.getBytes( parameterIndex); } catch (SQLException e) { handleException(e); return null; } }
  110. public Date getDate(int parameterIndex) throws SQLException
  111. { checkOpen(); try { return _stmt.getDate( parameterIndex); } catch (SQLException e) { handleException(e); return null; } }
  112. public Time getTime(int parameterIndex) throws SQLException
  113. { checkOpen(); try { return _stmt.getTime( parameterIndex); } catch (SQLException e) { handleException(e); return null; } }
  114. public Timestamp getTimestamp(int parameterIndex) throws SQLException
  115. { checkOpen(); try { return _stmt.getTimestamp( parameterIndex); } catch (SQLException e) { handleException(e); return null; } }
  116. public Object getObject(int parameterIndex) throws SQLException
  117. { checkOpen(); try { return _stmt.getObject( parameterIndex); } catch (SQLException e) { handleException(e); return null; } }
  118. public BigDecimal getBigDecimal(int parameterIndex) throws SQLException
  119. { checkOpen(); try { return _stmt.getBigDecimal( parameterIndex); } catch (SQLException e) { handleException(e); return null; } }
  120. public Object getObject(int i, Map map) throws SQLException
  121. { checkOpen(); try { return _stmt.getObject( i, map); } catch (SQLException e) { handleException(e); return null; } }
  122. public Ref getRef(int i) throws SQLException
  123. { checkOpen(); try { return _stmt.getRef( i); } catch (SQLException e) { handleException(e); return null; } }
  124. public Blob getBlob(int i) throws SQLException
  125. { checkOpen(); try { return _stmt.getBlob( i); } catch (SQLException e) { handleException(e); return null; } }
  126. public Clob getClob(int i) throws SQLException
  127. { checkOpen(); try { return _stmt.getClob( i); } catch (SQLException e) { handleException(e); return null; } }
  128. public Array getArray(int i) throws SQLException
  129. { checkOpen(); try { return _stmt.getArray( i); } catch (SQLException e) { handleException(e); return null; } }
  130. public Date getDate(int parameterIndex, Calendar cal) throws SQLException
  131. { checkOpen(); try { return _stmt.getDate( parameterIndex, cal); } catch (SQLException e) { handleException(e); return null; } }
  132. public Time getTime(int parameterIndex, Calendar cal) throws SQLException
  133. { checkOpen(); try { return _stmt.getTime( parameterIndex, cal); } catch (SQLException e) { handleException(e); return null; } }
  134. public Timestamp getTimestamp(int parameterIndex, Calendar cal) throws SQLException
  135. { checkOpen(); try { return _stmt.getTimestamp( parameterIndex, cal); } catch (SQLException e) { handleException(e); return null; } }
  136. public void registerOutParameter(int paramIndex, int sqlType, String typeName) throws SQLException
  137. { checkOpen(); try { _stmt.registerOutParameter( paramIndex, sqlType, typeName); } catch (SQLException e) { handleException(e); } }
  138. // ------------------- JDBC 3.0 -----------------------------------------
  139. // Will be commented by the build process on a JDBC 2.0 system
  140. /* JDBC_3_ANT_KEY_BEGIN */
  141. public void registerOutParameter(String parameterName, int sqlType) throws SQLException
  142. { checkOpen(); try { _stmt.registerOutParameter(parameterName, sqlType); } catch (SQLException e) { handleException(e); } }
  143. public void registerOutParameter(String parameterName, int sqlType, int scale) throws SQLException
  144. { checkOpen(); try { _stmt.registerOutParameter(parameterName, sqlType, scale); } catch (SQLException e) { handleException(e); } }
  145. public void registerOutParameter(String parameterName, int sqlType, String typeName) throws SQLException
  146. { checkOpen(); try { _stmt.registerOutParameter(parameterName, sqlType, typeName); } catch (SQLException e) { handleException(e); } }
  147. public URL getURL(int parameterIndex) throws SQLException
  148. { checkOpen(); try { return _stmt.getURL(parameterIndex); } catch (SQLException e) { handleException(e); return null; } }
  149. public void setURL(String parameterName, URL val) throws SQLException
  150. { checkOpen(); try { _stmt.setURL(parameterName, val); } catch (SQLException e) { handleException(e); } }
  151. public void setNull(String parameterName, int sqlType) throws SQLException
  152. { checkOpen(); try { _stmt.setNull(parameterName, sqlType); } catch (SQLException e) { handleException(e); } }
  153. public void setBoolean(String parameterName, boolean x) throws SQLException
  154. { checkOpen(); try { _stmt.setBoolean(parameterName, x); } catch (SQLException e) { handleException(e); } }
  155. public void setByte(String parameterName, byte x) throws SQLException
  156. { checkOpen(); try { _stmt.setByte(parameterName, x); } catch (SQLException e) { handleException(e); } }
  157. public void setShort(String parameterName, short x) throws SQLException
  158. { checkOpen(); try { _stmt.setShort(parameterName, x); } catch (SQLException e) { handleException(e); } }
  159. public void setInt(String parameterName, int x) throws SQLException
  160. { checkOpen(); try { _stmt.setInt(parameterName, x); } catch (SQLException e) { handleException(e); } }
  161. public void setLong(String parameterName, long x) throws SQLException
  162. { checkOpen(); try { _stmt.setLong(parameterName, x); } catch (SQLException e) { handleException(e); } }
  163. public void setFloat(String parameterName, float x) throws SQLException
  164. { checkOpen(); try { _stmt.setFloat(parameterName, x); } catch (SQLException e) { handleException(e); } }
  165. public void setDouble(String parameterName, double x) throws SQLException
  166. { checkOpen(); try { _stmt.setDouble(parameterName, x); } catch (SQLException e) { handleException(e); } }
  167. public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException
  168. { checkOpen(); try { _stmt.setBigDecimal(parameterName, x); } catch (SQLException e) { handleException(e); } }
  169. public void setString(String parameterName, String x) throws SQLException
  170. { checkOpen(); try { _stmt.setString(parameterName, x); } catch (SQLException e) { handleException(e); } }
  171. public void setBytes(String parameterName, byte [] x) throws SQLException
  172. { checkOpen(); try { _stmt.setBytes(parameterName, x); } catch (SQLException e) { handleException(e); } }
  173. public void setDate(String parameterName, Date x) throws SQLException
  174. { checkOpen(); try { _stmt.setDate(parameterName, x); } catch (SQLException e) { handleException(e); } }
  175. public void setTime(String parameterName, Time x) throws SQLException
  176. { checkOpen(); try { _stmt.setTime(parameterName, x); } catch (SQLException e) { handleException(e); } }
  177. public void setTimestamp(String parameterName, Timestamp x) throws SQLException
  178. { checkOpen(); try { _stmt.setTimestamp(parameterName, x); } catch (SQLException e) { handleException(e); } }
  179. public void setAsciiStream(String parameterName, InputStream x, int length) throws SQLException
  180. { checkOpen(); try { _stmt.setAsciiStream(parameterName, x, length); } catch (SQLException e) { handleException(e); } }
  181. public void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException
  182. { checkOpen(); try { _stmt.setBinaryStream(parameterName, x, length); } catch (SQLException e) { handleException(e); } }
  183. public void setObject(String parameterName, Object x, int targetSqlType, int scale) throws SQLException
  184. { checkOpen(); try { _stmt.setObject(parameterName, x, targetSqlType, scale); } catch (SQLException e) { handleException(e); } }
  185. public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException
  186. { checkOpen(); try { _stmt.setObject(parameterName, x, targetSqlType); } catch (SQLException e) { handleException(e); } }
  187. public void setObject(String parameterName, Object x) throws SQLException
  188. { checkOpen(); try { _stmt.setObject(parameterName, x); } catch (SQLException e) { handleException(e); } }
  189. public void setCharacterStream(String parameterName, Reader reader, int length) throws SQLException
  190. { checkOpen(); _stmt.setCharacterStream(parameterName, reader, length); }
  191. public void setDate(String parameterName, Date x, Calendar cal) throws SQLException
  192. { checkOpen(); try { _stmt.setDate(parameterName, x, cal); } catch (SQLException e) { handleException(e); } }
  193. public void setTime(String parameterName, Time x, Calendar cal) throws SQLException
  194. { checkOpen(); try { _stmt.setTime(parameterName, x, cal); } catch (SQLException e) { handleException(e); } }
  195. public void setTimestamp(String parameterName, Timestamp x, Calendar cal) throws SQLException
  196. { checkOpen(); try { _stmt.setTimestamp(parameterName, x, cal); } catch (SQLException e) { handleException(e); } }
  197. public void setNull(String parameterName, int sqlType, String typeName) throws SQLException
  198. { checkOpen(); try { _stmt.setNull(parameterName, sqlType, typeName); } catch (SQLException e) { handleException(e); } }
  199. public String getString(String parameterName) throws SQLException
  200. { checkOpen(); try { return _stmt.getString(parameterName); } catch (SQLException e) { handleException(e); return null; } }
  201. public boolean getBoolean(String parameterName) throws SQLException
  202. { checkOpen(); try { return _stmt.getBoolean(parameterName); } catch (SQLException e) { handleException(e); return false; } }
  203. public byte getByte(String parameterName) throws SQLException
  204. { checkOpen(); try { return _stmt.getByte(parameterName); } catch (SQLException e) { handleException(e); return 0; } }
  205. public short getShort(String parameterName) throws SQLException
  206. { checkOpen(); try { return _stmt.getShort(parameterName); } catch (SQLException e) { handleException(e); return 0; } }
  207. public int getInt(String parameterName) throws SQLException
  208. { checkOpen(); try { return _stmt.getInt(parameterName); } catch (SQLException e) { handleException(e); return 0; } }
  209. public long getLong(String parameterName) throws SQLException
  210. { checkOpen(); try { return _stmt.getLong(parameterName); } catch (SQLException e) { handleException(e); return 0; } }
  211. public float getFloat(String parameterName) throws SQLException
  212. { checkOpen(); try { return _stmt.getFloat(parameterName); } catch (SQLException e) { handleException(e); return 0; } }
  213. public double getDouble(String parameterName) throws SQLException
  214. { checkOpen(); try { return _stmt.getDouble(parameterName); } catch (SQLException e) { handleException(e); return 0; } }
  215. public byte[] getBytes(String parameterName) throws SQLException
  216. { checkOpen(); try { return _stmt.getBytes(parameterName); } catch (SQLException e) { handleException(e); return null; } }
  217. public Date getDate(String parameterName) throws SQLException
  218. { checkOpen(); try { return _stmt.getDate(parameterName); } catch (SQLException e) { handleException(e); return null; } }
  219. public Time getTime(String parameterName) throws SQLException
  220. { checkOpen(); try { return _stmt.getTime(parameterName); } catch (SQLException e) { handleException(e); return null; } }
  221. public Timestamp getTimestamp(String parameterName) throws SQLException
  222. { checkOpen(); try { return _stmt.getTimestamp(parameterName); } catch (SQLException e) { handleException(e); return null; } }
  223. public Object getObject(String parameterName) throws SQLException
  224. { checkOpen(); try { return _stmt.getObject(parameterName); } catch (SQLException e) { handleException(e); return null; } }
  225. public BigDecimal getBigDecimal(String parameterName) throws SQLException
  226. { checkOpen(); try { return _stmt.getBigDecimal(parameterName); } catch (SQLException e) { handleException(e); return null; } }
  227. public Object getObject(String parameterName, Map map) throws SQLException
  228. { checkOpen(); try { return _stmt.getObject(parameterName, map); } catch (SQLException e) { handleException(e); return null; } }
  229. public Ref getRef(String parameterName) throws SQLException
  230. { checkOpen(); try { return _stmt.getRef(parameterName); } catch (SQLException e) { handleException(e); return null; } }
  231. public Blob getBlob(String parameterName) throws SQLException
  232. { checkOpen(); try { return _stmt.getBlob(parameterName); } catch (SQLException e) { handleException(e); return null; } }
  233. public Clob getClob(String parameterName) throws SQLException
  234. { checkOpen(); try { return _stmt.getClob(parameterName); } catch (SQLException e) { handleException(e); return null; } }
  235. public Array getArray(String parameterName) throws SQLException
  236. { checkOpen(); try { return _stmt.getArray(parameterName); } catch (SQLException e) { handleException(e); return null; } }
  237. public Date getDate(String parameterName, Calendar cal) throws SQLException
  238. { checkOpen(); try { return _stmt.getDate(parameterName, cal); } catch (SQLException e) { handleException(e); return null; } }
  239. public Time getTime(String parameterName, Calendar cal) throws SQLException
  240. { checkOpen(); try { return _stmt.getTime(parameterName, cal); } catch (SQLException e) { handleException(e); return null; } }
  241. public Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException
  242. { checkOpen(); try { return _stmt.getTimestamp(parameterName, cal); } catch (SQLException e) { handleException(e); return null; } }
  243. public URL getURL(String parameterName) throws SQLException
  244. { checkOpen(); try { return _stmt.getURL(parameterName); } catch (SQLException e) { handleException(e); return null; } }
  245. /* JDBC_3_ANT_KEY_END */
  246. }