1 22 package org.jboss.resource.adapter.jdbc; 23 24 import java.io.InputStream ; 25 import java.io.Reader ; 26 import java.math.BigDecimal ; 27 import java.net.URL ; 28 import java.sql.Array ; 29 import java.sql.Blob ; 30 import java.sql.Clob ; 31 import java.sql.Date ; 32 import java.sql.ParameterMetaData ; 33 import java.sql.PreparedStatement ; 34 import java.sql.Ref ; 35 import java.sql.ResultSet ; 36 import java.sql.ResultSetMetaData ; 37 import java.sql.SQLException ; 38 import java.sql.Statement ; 39 import java.sql.Time ; 40 import java.sql.Timestamp ; 41 import java.util.Calendar ; 42 43 50 public class WrappedPreparedStatement extends WrappedStatement implements PreparedStatement 51 { 52 private final PreparedStatement ps; 53 54 public WrappedPreparedStatement(final WrappedConnection lc, final PreparedStatement ps) 55 { 56 super(lc, ps); 57 this.ps = ps; 58 } 59 60 public Statement getUnderlyingStatement() throws SQLException 61 { 62 checkState(); 63 if (ps instanceof CachedPreparedStatement) 64 { 65 return ((CachedPreparedStatement)ps).getUnderlyingPreparedStatement(); 66 } 67 else 68 { 69 return ps; 70 } 71 } 72 73 public void setBoolean(int parameterIndex, boolean value) throws SQLException 74 { 75 checkState(); 76 try 77 { 78 ps.setBoolean(parameterIndex, value); 79 } 80 catch (Throwable t) 81 { 82 throw checkException(t); 83 } 84 } 85 86 public void setByte(int parameterIndex, byte value) throws SQLException 87 { 88 checkState(); 89 try 90 { 91 ps.setByte(parameterIndex, value); 92 } 93 catch (Throwable t) 94 { 95 throw checkException(t); 96 } 97 } 98 99 public void setShort(int parameterIndex, short value) throws SQLException 100 { 101 checkState(); 102 try 103 { 104 ps.setShort(parameterIndex, value); 105 } 106 catch (Throwable t) 107 { 108 throw checkException(t); 109 } 110 } 111 112 public void setInt(int parameterIndex, int value) throws SQLException 113 { 114 checkState(); 115 try 116 { 117 ps.setInt(parameterIndex, value); 118 } 119 catch (Throwable t) 120 { 121 throw checkException(t); 122 } 123 } 124 125 public void setLong(int parameterIndex, long value) throws SQLException 126 { 127 checkState(); 128 try 129 { 130 ps.setLong(parameterIndex, value); 131 } 132 catch (Throwable t) 133 { 134 throw checkException(t); 135 } 136 } 137 138 public void setFloat(int parameterIndex, float value) throws SQLException 139 { 140 checkState(); 141 try 142 { 143 ps.setFloat(parameterIndex, value); 144 } 145 catch (Throwable t) 146 { 147 throw checkException(t); 148 } 149 } 150 151 public void setDouble(int parameterIndex, double value) throws SQLException 152 { 153 checkState(); 154 try 155 { 156 ps.setDouble(parameterIndex, value); 157 } 158 catch (Throwable t) 159 { 160 throw checkException(t); 161 } 162 } 163 164 public void setURL(int parameterIndex, URL value) throws SQLException 165 { 166 checkState(); 167 try 168 { 169 ps.setURL(parameterIndex, value); 170 } 171 catch (Throwable t) 172 { 173 throw checkException(t); 174 } 175 } 176 177 public void setTime(int parameterIndex, Time value) throws SQLException 178 { 179 checkState(); 180 try 181 { 182 ps.setTime(parameterIndex, value); 183 } 184 catch (Throwable t) 185 { 186 throw checkException(t); 187 } 188 } 189 190 public void setTime(int parameterIndex, Time value, Calendar calendar) throws SQLException 191 { 192 checkState(); 193 try 194 { 195 ps.setTime(parameterIndex, value, calendar); 196 } 197 catch (Throwable t) 198 { 199 throw checkException(t); 200 } 201 } 202 203 public boolean execute() throws SQLException 204 { 205 checkTransaction(); 206 try 207 { 208 checkConfiguredQueryTimeout(); 209 return ps.execute(); 210 } 211 catch (Throwable t) 212 { 213 throw checkException(t); 214 } 215 } 216 217 public ResultSetMetaData getMetaData() throws SQLException 218 { 219 checkState(); 220 try 221 { 222 return ps.getMetaData(); 223 } 224 catch (Throwable t) 225 { 226 throw checkException(t); 227 } 228 } 229 230 public ResultSet executeQuery() throws SQLException 231 { 232 checkTransaction(); 233 try 234 { 235 checkConfiguredQueryTimeout(); 236 ResultSet resultSet = ps.executeQuery(); 237 return registerResultSet(resultSet); 238 } 239 catch (Throwable t) 240 { 241 throw checkException(t); 242 } 243 } 244 245 public int executeUpdate() throws SQLException 246 { 247 checkTransaction(); 248 try 249 { 250 checkConfiguredQueryTimeout(); 251 return ps.executeUpdate(); 252 } 253 catch (Throwable t) 254 { 255 throw checkException(t); 256 } 257 } 258 259 public void addBatch() throws SQLException 260 { 261 checkState(); 262 try 263 { 264 ps.addBatch(); 265 } 266 catch (Throwable t) 267 { 268 throw checkException(t); 269 } 270 } 271 272 public void setNull(int parameterIndex, int sqlType) throws SQLException 273 { 274 checkState(); 275 try 276 { 277 ps.setNull(parameterIndex, sqlType); 278 } 279 catch (Throwable t) 280 { 281 throw checkException(t); 282 } 283 } 284 285 public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException 286 { 287 checkState(); 288 try 289 { 290 ps.setNull(parameterIndex, sqlType, typeName); 291 } 292 catch (Throwable t) 293 { 294 throw checkException(t); 295 } 296 } 297 298 public void setBigDecimal(int parameterIndex, BigDecimal value) throws SQLException 299 { 300 checkState(); 301 try 302 { 303 ps.setBigDecimal(parameterIndex, value); 304 } 305 catch (Throwable t) 306 { 307 throw checkException(t); 308 } 309 } 310 311 public void setString(int parameterIndex, String value) throws SQLException 312 { 313 checkState(); 314 try 315 { 316 ps.setString(parameterIndex, value); 317 } 318 catch (Throwable t) 319 { 320 throw checkException(t); 321 } 322 } 323 324 public void setBytes(int parameterIndex, byte[] value) throws SQLException 325 { 326 checkState(); 327 try 328 { 329 ps.setBytes(parameterIndex, value); 330 } 331 catch (Throwable t) 332 { 333 throw checkException(t); 334 } 335 } 336 337 public void setDate(int parameterIndex, Date value) throws SQLException 338 { 339 checkState(); 340 try 341 { 342 ps.setDate(parameterIndex, value); 343 } 344 catch (Throwable t) 345 { 346 throw checkException(t); 347 } 348 } 349 350 public void setDate(int parameterIndex, Date value, Calendar calendar) throws SQLException 351 { 352 checkState(); 353 try 354 { 355 ps.setDate(parameterIndex, value, calendar); 356 } 357 catch (Throwable t) 358 { 359 throw checkException(t); 360 } 361 } 362 363 public void setTimestamp(int parameterIndex, Timestamp value) throws SQLException 364 { 365 checkState(); 366 try 367 { 368 ps.setTimestamp(parameterIndex, value); 369 } 370 catch (Throwable t) 371 { 372 throw checkException(t); 373 } 374 } 375 376 public void setTimestamp(int parameterIndex, Timestamp value, Calendar calendar) throws SQLException 377 { 378 checkState(); 379 try 380 { 381 ps.setTimestamp(parameterIndex, value, calendar); 382 } 383 catch (Throwable t) 384 { 385 throw checkException(t); 386 } 387 } 388 389 392 public void setAsciiStream(int parameterIndex, InputStream stream, int length) throws SQLException 393 { 394 checkState(); 395 try 396 { 397 ps.setAsciiStream(parameterIndex, stream, length); 398 } 399 catch (Throwable t) 400 { 401 throw checkException(t); 402 } 403 } 404 405 408 public void setUnicodeStream(int parameterIndex, InputStream stream, int length) throws SQLException 409 { 410 checkState(); 411 try 412 { 413 ps.setUnicodeStream(parameterIndex, stream, length); 414 } 415 catch (Throwable t) 416 { 417 throw checkException(t); 418 } 419 } 420 421 public void setBinaryStream(int parameterIndex, InputStream stream, int length) throws SQLException 422 { 423 checkState(); 424 try 425 { 426 ps.setBinaryStream(parameterIndex, stream, length); 427 } 428 catch (Throwable t) 429 { 430 throw checkException(t); 431 } 432 } 433 434 public void clearParameters() throws SQLException 435 { 436 checkState(); 437 try 438 { 439 ps.clearParameters(); 440 } 441 catch (Throwable t) 442 { 443 throw checkException(t); 444 } 445 } 446 447 public void setObject(int parameterIndex, Object value, int sqlType, int scale) throws SQLException 448 { 449 checkState(); 450 try 451 { 452 ps.setObject(parameterIndex, value, sqlType, scale); 453 } 454 catch (Throwable t) 455 { 456 throw checkException(t); 457 } 458 } 459 460 public void setObject(int parameterIndex, Object value, int sqlType) throws SQLException 461 { 462 checkState(); 463 try 464 { 465 ps.setObject(parameterIndex, value, sqlType); 466 } 467 catch (Throwable t) 468 { 469 throw checkException(t); 470 } 471 } 472 473 public void setObject(int parameterIndex, Object value) throws SQLException 474 { 475 checkState(); 476 try 477 { 478 ps.setObject(parameterIndex, value); 479 } 480 catch (Throwable t) 481 { 482 throw checkException(t); 483 } 484 } 485 486 public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException 487 { 488 checkState(); 489 try 490 { 491 ps.setCharacterStream(parameterIndex, reader, length); 492 } 493 catch (Throwable t) 494 { 495 throw checkException(t); 496 } 497 } 498 499 public void setRef(int parameterIndex, Ref value) throws SQLException 500 { 501 checkState(); 502 try 503 { 504 ps.setRef(parameterIndex, value); 505 } 506 catch (Throwable t) 507 { 508 throw checkException(t); 509 } 510 } 511 512 public void setBlob(int parameterIndex, Blob value) throws SQLException 513 { 514 checkState(); 515 try 516 { 517 ps.setBlob(parameterIndex, value); 518 } 519 catch (Throwable t) 520 { 521 throw checkException(t); 522 } 523 } 524 525 public void setClob(int parameterIndex, Clob value) throws SQLException 526 { 527 checkState(); 528 try 529 { 530 ps.setClob(parameterIndex, value); 531 } 532 catch (Throwable t) 533 { 534 throw checkException(t); 535 } 536 } 537 538 public void setArray(int parameterIndex, Array value) throws SQLException 539 { 540 checkState(); 541 try 542 { 543 ps.setArray(parameterIndex, value); 544 } 545 catch (Throwable t) 546 { 547 throw checkException(t); 548 } 549 } 550 551 public ParameterMetaData getParameterMetaData() throws SQLException 552 { 553 checkState(); 554 try 555 { 556 return ps.getParameterMetaData(); 557 } 558 catch (Throwable t) 559 { 560 throw checkException(t); 561 } 562 } 563 } 564 | Popular Tags |