1 4 package org.ofbiz.minerva.pool.jdbc; 5 6 import java.io.InputStream ; 7 import java.io.Reader ; 8 import java.math.BigDecimal ; 9 import java.net.URL ; 10 import java.sql.Array ; 11 import java.sql.Blob ; 12 import java.sql.Clob ; 13 import java.sql.Date ; 14 import java.sql.ParameterMetaData ; 15 import java.sql.PreparedStatement ; 16 import java.sql.Ref ; 17 import java.sql.ResultSet ; 18 import java.sql.ResultSetMetaData ; 19 import java.sql.SQLException ; 20 import java.sql.Time ; 21 import java.sql.Timestamp ; 22 import java.util.Calendar ; 23 24 30 public class PreparedStatementInPool extends StatementInPool implements PreparedStatement { 31 32 private final static String CLOSED = "PreparedStatement has been closed!"; 33 private PreparedStatement impl; 34 private ConnectionWrapper con; 35 private String sql; 36 37 40 public PreparedStatementInPool(PreparedStatement source, ConnectionWrapper owner, String sql) { 41 super(source, owner); 42 if (source == null || owner == null) throw new NullPointerException (); 43 impl = source; 44 con = owner; 45 this.sql = sql; 46 } 47 48 54 public PreparedStatement getUnderlyingPreparedStatement() { 55 return impl; 56 } 57 58 61 public String getSql() { 62 return sql; 63 } 64 65 67 public ResultSet executeQuery() throws SQLException { 68 if (impl == null) throw new SQLException (CLOSED); 69 try { 70 setLastUsed(); 71 return new ResultSetInPool(impl.executeQuery(), this); 72 } catch (SQLException e) { 73 setError(e); 74 throw e; 75 } 76 } 77 78 public int executeUpdate() throws SQLException { 79 if (impl == null) throw new SQLException (CLOSED); 80 try { 81 setLastUsed(); 82 return impl.executeUpdate(); 83 } catch (SQLException e) { 84 setError(e); 85 throw e; 86 } 87 } 88 89 public void setNull(int parameterIndex, int sqlType) throws SQLException { 90 if (impl == null) throw new SQLException (CLOSED); 91 try { 92 impl.setNull(parameterIndex, sqlType); 93 } catch (SQLException e) { 94 setError(e); 95 throw e; 96 } 97 } 98 99 public void setBoolean(int parameterIndex, boolean x) throws SQLException { 100 if (impl == null) throw new SQLException (CLOSED); 101 try { 102 impl.setBoolean(parameterIndex, x); 103 } catch (SQLException e) { 104 setError(e); 105 throw e; 106 } 107 } 108 109 public void setByte(int parameterIndex, byte x) throws SQLException { 110 if (impl == null) throw new SQLException (CLOSED); 111 try { 112 impl.setByte(parameterIndex, x); 113 } catch (SQLException e) { 114 setError(e); 115 throw e; 116 } 117 } 118 119 public void setShort(int parameterIndex, short x) throws SQLException { 120 if (impl == null) throw new SQLException (CLOSED); 121 try { 122 impl.setShort(parameterIndex, x); 123 } catch (SQLException e) { 124 setError(e); 125 throw e; 126 } 127 } 128 129 public void setInt(int parameterIndex, int x) throws SQLException { 130 if (impl == null) throw new SQLException (CLOSED); 131 try { 132 impl.setInt(parameterIndex, x); 133 } catch (SQLException e) { 134 setError(e); 135 throw e; 136 } 137 } 138 139 public void setLong(int parameterIndex, long x) throws SQLException { 140 if (impl == null) throw new SQLException (CLOSED); 141 try { 142 impl.setLong(parameterIndex, x); 143 } catch (SQLException e) { 144 setError(e); 145 throw e; 146 } 147 } 148 149 public void setFloat(int parameterIndex, float x) throws SQLException { 150 if (impl == null) throw new SQLException (CLOSED); 151 try { 152 impl.setFloat(parameterIndex, x); 153 } catch (SQLException e) { 154 setError(e); 155 throw e; 156 } 157 } 158 159 public void setDouble(int parameterIndex, double x) throws SQLException { 160 if (impl == null) throw new SQLException (CLOSED); 161 try { 162 impl.setDouble(parameterIndex, x); 163 } catch (SQLException e) { 164 setError(e); 165 throw e; 166 } 167 } 168 169 public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { 170 if (impl == null) throw new SQLException (CLOSED); 171 try { 172 impl.setBigDecimal(parameterIndex, x); 173 } catch (SQLException e) { 174 setError(e); 175 throw e; 176 } 177 } 178 179 public void setString(int parameterIndex, String x) throws SQLException { 180 if (impl == null) throw new SQLException (CLOSED); 181 try { 182 impl.setString(parameterIndex, x); 183 } catch (SQLException e) { 184 setError(e); 185 throw e; 186 } 187 } 188 189 public void setBytes(int parameterIndex, byte[] x) throws SQLException { 190 if (impl == null) throw new SQLException (CLOSED); 191 try { 192 impl.setBytes(parameterIndex, x); 193 } catch (SQLException e) { 194 setError(e); 195 throw e; 196 } 197 } 198 199 public void setDate(int parameterIndex, Date x) throws SQLException { 200 if (impl == null) throw new SQLException (CLOSED); 201 try { 202 impl.setDate(parameterIndex, x); 203 } catch (SQLException e) { 204 setError(e); 205 throw e; 206 } 207 } 208 209 public void setTime(int parameterIndex, Time x) throws SQLException { 210 if (impl == null) throw new SQLException (CLOSED); 211 try { 212 impl.setTime(parameterIndex, x); 213 } catch (SQLException e) { 214 setError(e); 215 throw e; 216 } 217 } 218 219 public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { 220 if (impl == null) throw new SQLException (CLOSED); 221 try { 222 impl.setTimestamp(parameterIndex, x); 223 } catch (SQLException e) { 224 setError(e); 225 throw e; 226 } 227 } 228 229 public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException { 230 if (impl == null) throw new SQLException (CLOSED); 231 try { 232 impl.setAsciiStream(parameterIndex, x, length); 233 } catch (SQLException e) { 234 setError(e); 235 throw e; 236 } 237 } 238 239 public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException { 240 if (impl == null) throw new SQLException (CLOSED); 241 try { 242 impl.setUnicodeStream(parameterIndex, x, length); 243 } catch (SQLException e) { 244 setError(e); 245 throw e; 246 } 247 } 248 249 public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException { 250 if (impl == null) throw new SQLException (CLOSED); 251 try { 252 impl.setBinaryStream(parameterIndex, x, length); 253 } catch (SQLException e) { 254 setError(e); 255 throw e; 256 } 257 } 258 259 public void clearParameters() throws SQLException { 260 if (impl == null) throw new SQLException (CLOSED); 261 try { 262 impl.clearParameters(); 263 } catch (SQLException e) { 264 setError(e); 265 throw e; 266 } 267 } 268 269 public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException { 270 if (impl == null) throw new SQLException (CLOSED); 271 try { 272 impl.setObject(parameterIndex, x, targetSqlType, scale); 273 } catch (SQLException e) { 274 setError(e); 275 throw e; 276 } 277 } 278 279 public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { 280 if (impl == null) throw new SQLException (CLOSED); 281 try { 282 impl.setObject(parameterIndex, x, targetSqlType); 283 } catch (SQLException e) { 284 setError(e); 285 throw e; 286 } 287 } 288 289 public void setObject(int parameterIndex, Object x) throws SQLException { 290 if (impl == null) throw new SQLException (CLOSED); 291 try { 292 impl.setObject(parameterIndex, x); 293 } catch (SQLException e) { 294 setError(e); 295 throw e; 296 } 297 } 298 299 public boolean execute() throws SQLException { 300 if (impl == null) throw new SQLException (CLOSED); 301 try { 302 setLastUsed(); 303 return impl.execute(); 304 } catch (SQLException e) { 305 setError(e); 306 throw e; 307 } 308 } 309 310 public void addBatch() throws SQLException { 311 if (impl == null) throw new SQLException (CLOSED); 312 try { 313 impl.addBatch(); 314 } catch (SQLException e) { 315 setError(e); 316 throw e; 317 } 318 } 319 320 public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException { 321 if (impl == null) throw new SQLException (CLOSED); 322 try { 323 impl.setCharacterStream(parameterIndex, reader, length); 324 } catch (SQLException e) { 325 setError(e); 326 throw e; 327 } 328 } 329 330 public void setRef(int i, Ref x) throws SQLException { 331 if (impl == null) throw new SQLException (CLOSED); 332 try { 333 impl.setRef(i, x); 334 } catch (SQLException e) { 335 setError(e); 336 throw e; 337 } 338 } 339 340 public void setBlob(int i, Blob x) throws SQLException { 341 if (impl == null) throw new SQLException (CLOSED); 342 try { 343 impl.setBlob(i, x); 344 } catch (SQLException e) { 345 setError(e); 346 throw e; 347 } 348 } 349 350 public void setClob(int i, Clob x) throws SQLException { 351 if (impl == null) throw new SQLException (CLOSED); 352 try { 353 impl.setClob(i, x); 354 } catch (SQLException e) { 355 setError(e); 356 throw e; 357 } 358 } 359 360 public void setArray(int i, Array x) throws SQLException { 361 if (impl == null) throw new SQLException (CLOSED); 362 try { 363 impl.setArray(i, x); 364 } catch (SQLException e) { 365 setError(e); 366 throw e; 367 } 368 } 369 370 public ResultSetMetaData getMetaData() throws SQLException { 371 if (impl == null) throw new SQLException (CLOSED); 372 try { 373 return impl.getMetaData(); 374 } catch (SQLException e) { 375 setError(e); 376 throw e; 377 } 378 } 379 380 public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException { 381 if (impl == null) throw new SQLException (CLOSED); 382 try { 383 impl.setDate(parameterIndex, x, cal); 384 } catch (SQLException e) { 385 setError(e); 386 throw e; 387 } 388 } 389 390 public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException { 391 if (impl == null) throw new SQLException (CLOSED); 392 try { 393 impl.setTime(parameterIndex, x, cal); 394 } catch (SQLException e) { 395 setError(e); 396 throw e; 397 } 398 } 399 400 public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException { 401 if (impl == null) throw new SQLException (CLOSED); 402 try { 403 impl.setTimestamp(parameterIndex, x, cal); 404 } catch (SQLException e) { 405 setError(e); 406 throw e; 407 } 408 } 409 410 public void setNull(int paramIndex, int sqlType, String typeName) throws SQLException { 411 if (impl == null) throw new SQLException (CLOSED); 412 try { 413 impl.setNull(paramIndex, sqlType, typeName); 414 } catch (SQLException e) { 415 setError(e); 416 throw e; 417 } 418 } 419 420 public void close() throws SQLException { 421 if (con != null) { 422 con.statementClosed(this); 423 } 424 super.clearFields(); 425 con = null; 426 impl = null; 427 sql = null; 428 } 429 430 432 435 public void setURL(int arg0, URL arg1) throws SQLException { 436 438 } 439 440 443 public ParameterMetaData getParameterMetaData() throws SQLException { 444 return null; 446 } 447 } 448 | Popular Tags |