1 25 26 27 package org.objectweb.jonas.jdbc_xa; 28 29 import java.sql.*; 30 import java.util.Map ; 31 32 import org.objectweb.jonas.common.Log; 33 import org.objectweb.util.monolog.api.Logger; 34 import org.objectweb.util.monolog.api.BasicLevel; 35 36 44 public class ConnectionImpl implements Connection { 45 46 static private Logger logger = null; 47 48 protected Connection actConn = null; 49 protected XAConnectionImpl xac = null; 50 protected boolean autocommit_set = false; 51 protected boolean autocommit_unset = false; 52 static private Class implclass = null; 53 54 58 60 public ConnectionImpl(XAConnectionImpl xac, Connection actual) { 61 this.xac = xac; 62 actConn = actual; 63 logger = Log.getLogger(Log.JONAS_JDBCXA_PREFIX); 64 } 65 66 67 68 72 75 public Connection getConnection() { 76 if (logger.isLoggable(BasicLevel.DEBUG)) { 77 logger.log(BasicLevel.DEBUG, ""); 78 } 79 return actConn; 80 } 81 82 87 public Statement createStatement() 88 throws SQLException { 89 if (logger.isLoggable(BasicLevel.DEBUG)) { 90 logger.log(BasicLevel.DEBUG, ""); 91 } 92 try { 93 return actConn.createStatement(); 94 } catch (SQLException e) { 95 xac.notifyError(e); 96 throw(e); 97 } 98 } 99 100 101 102 public PreparedStatement prepareStatement(String sql) 103 throws SQLException { 104 if (logger.isLoggable(BasicLevel.DEBUG)) { 105 logger.log(BasicLevel.DEBUG, ""); 106 } 107 try { 108 return actConn.prepareStatement(sql); 109 } catch (SQLException e) { 110 xac.notifyError(e); 111 throw(e); 112 } 113 } 114 115 public CallableStatement prepareCall(String sql) 116 throws SQLException { 117 if (logger.isLoggable(BasicLevel.DEBUG)) { 118 logger.log(BasicLevel.DEBUG, ""); 119 } 120 try { 121 return actConn.prepareCall(sql); 122 } catch (SQLException e) { 123 xac.notifyError(e); 124 throw(e); 125 } 126 } 127 128 public String nativeSQL(String sql) 129 throws SQLException { 130 if (logger.isLoggable(BasicLevel.DEBUG)) { 131 logger.log(BasicLevel.DEBUG, ""); 132 } 133 try { 134 return actConn.nativeSQL(sql); 135 } catch (SQLException e) { 136 xac.notifyError(e); 137 throw(e); 138 } 139 } 140 141 public boolean isPhysicallyClosed() 142 throws SQLException { 143 if (logger.isLoggable(BasicLevel.DEBUG)) { 144 logger.log(BasicLevel.DEBUG, ""); 145 } 146 return actConn.isClosed(); 147 } 148 149 public boolean isClosed() 150 throws SQLException { 151 if (logger.isLoggable(BasicLevel.DEBUG)) { 152 logger.log(BasicLevel.DEBUG, ""); 153 } 154 155 try { 158 return actConn.isClosed(); 159 } catch (SQLException e) { 160 xac.notifyError(e); 161 throw(e); 162 } 163 } 164 165 public DatabaseMetaData getMetaData() 166 throws SQLException { 167 if (logger.isLoggable(BasicLevel.DEBUG)) { 168 logger.log(BasicLevel.DEBUG, ""); 169 } 170 try { 171 return actConn.getMetaData(); 172 } catch (SQLException e) { 173 xac.notifyError(e); 174 throw(e); 175 } 176 } 177 178 public void setReadOnly(boolean readOnly) 179 throws SQLException { 180 if (logger.isLoggable(BasicLevel.DEBUG)) { 181 logger.log(BasicLevel.DEBUG, ""); 182 } 183 try { 184 actConn.setReadOnly(readOnly); 185 } catch (SQLException e) { 186 xac.notifyError(e); 187 throw(e); 188 } 189 } 190 191 public boolean isReadOnly() 192 throws SQLException { 193 if (logger.isLoggable(BasicLevel.DEBUG)) { 194 logger.log(BasicLevel.DEBUG, ""); 195 } 196 try { 197 return actConn.isReadOnly(); 198 } catch (SQLException e) { 199 xac.notifyError(e); 200 throw(e); 201 } 202 } 203 204 public void setCatalog(String catalog) 205 throws SQLException { 206 if (logger.isLoggable(BasicLevel.DEBUG)) { 207 logger.log(BasicLevel.DEBUG, ""); 208 } 209 try { 210 actConn.setCatalog(catalog); 211 } catch (SQLException e) { 212 xac.notifyError(e); 213 throw(e); 214 } 215 } 216 217 public String getCatalog() 218 throws SQLException { 219 if (logger.isLoggable(BasicLevel.DEBUG)) { 220 logger.log(BasicLevel.DEBUG, ""); 221 } 222 try { 223 return actConn.getCatalog(); 224 } catch (SQLException e) { 225 xac.notifyError(e); 226 throw(e); 227 } 228 } 229 230 233 public void close() 234 throws SQLException { 235 if (logger.isLoggable(BasicLevel.DEBUG)) { 236 logger.log(BasicLevel.DEBUG, ""); 237 } 238 xac.notifyClose(); 239 } 240 241 public void setTransactionIsolation(int level) 242 throws SQLException { 243 if (logger.isLoggable(BasicLevel.DEBUG)) { 244 logger.log(BasicLevel.DEBUG, ""); 245 } 246 try { 247 actConn.setTransactionIsolation(level); 248 } catch (SQLException e) { 249 xac.notifyError(e); 250 throw(e); 251 } 252 } 253 254 public int getTransactionIsolation() 255 throws SQLException { 256 if (logger.isLoggable(BasicLevel.DEBUG)) { 257 logger.log(BasicLevel.DEBUG, ""); 258 } 259 try { 260 return actConn.getTransactionIsolation(); 261 } catch (SQLException e) { 262 xac.notifyError(e); 263 throw(e); 264 } 265 } 266 267 public SQLWarning getWarnings() 268 throws SQLException { 269 if (logger.isLoggable(BasicLevel.DEBUG)) { 270 logger.log(BasicLevel.DEBUG, ""); 271 } 272 try { 273 return actConn.getWarnings(); 274 } catch (SQLException e) { 275 xac.notifyError(e); 276 throw(e); 277 } 278 } 279 280 public void clearWarnings() 281 throws SQLException { 282 if (logger.isLoggable(BasicLevel.DEBUG)) { 283 logger.log(BasicLevel.DEBUG, ""); 284 } 285 try { 286 actConn.clearWarnings(); 287 } catch (SQLException e) { 288 xac.notifyError(e); 289 throw(e); 290 } 291 } 292 293 297 public void commit() 298 throws SQLException { 299 if (logger.isLoggable(BasicLevel.DEBUG)) { 300 logger.log(BasicLevel.DEBUG, "local transaction"); 301 } 302 try { 303 actConn.commit(); 304 } catch (SQLException e) { 305 xac.notifyError(e); 306 throw(e); 307 } 308 } 309 310 314 public void rollback() 315 throws SQLException { 316 if (logger.isLoggable(BasicLevel.DEBUG)) { 317 logger.log(BasicLevel.DEBUG, "local transaction"); 318 } 319 try { 320 actConn.rollback(); 321 } catch (SQLException e) { 322 xac.notifyError(e); 323 throw(e); 324 } 325 } 326 327 330 public void setAutoCommit(boolean autoCommit) 331 throws SQLException { 332 333 if (logger.isLoggable(BasicLevel.DEBUG)) { 334 logger.log(BasicLevel.DEBUG, " "); 335 } 336 try { 337 if (autoCommit == false) { 338 if (autocommit_unset == false) { actConn.setAutoCommit(false); 340 autocommit_set = false; 341 autocommit_unset = true; 342 } 343 } else { 344 if (autocommit_set == false) { actConn.setAutoCommit(true); 346 autocommit_set = true; 347 autocommit_unset = false; 348 } 349 } 350 } catch (SQLException e) { 351 String s = e.getMessage().toLowerCase(); 352 if (s.indexOf("set chained command not allowed") != -1) { 353 if (logger.isLoggable(BasicLevel.DEBUG)) { 354 logger.log(BasicLevel.DEBUG, "failed..."); 355 logger.log(BasicLevel.DEBUG, "Committing then retrying"); 356 } 357 try { 358 actConn.commit(); 361 actConn.setAutoCommit(autoCommit); if (logger.isLoggable(BasicLevel.DEBUG)) { 363 logger.log(BasicLevel.DEBUG, "succeeded after retry"); 364 } 365 } catch (SQLException se) { 366 logger.log(BasicLevel.ERROR,"" + autoCommit + ") failed again after retry", se); 367 xac.notifyError(e); 368 throw(e); 369 } 370 } else { 371 logger.log(BasicLevel.ERROR,"setAutoCommit(" + autoCommit + ") failed: "+e); 372 xac.notifyError(e); 373 throw(e); 374 } 375 } 376 } 377 378 381 public boolean getAutoCommit() 382 throws SQLException { 383 384 try { 385 return actConn.getAutoCommit(); 386 } catch (SQLException e) { 387 xac.notifyError(e); 388 throw(e); 389 } 390 } 391 392 public Statement createStatement(int resultSetType, int resultSetConcurrency) 393 throws SQLException { 394 395 if (logger.isLoggable(BasicLevel.DEBUG)) { 396 logger.log(BasicLevel.DEBUG, ""); 397 } 398 try { 399 return actConn.createStatement(resultSetType, resultSetConcurrency); 400 } catch (SQLException e) { 401 xac.notifyError(e); 402 throw(e); 403 } 404 } 405 406 public Map getTypeMap() 407 throws SQLException { 408 409 if (logger.isLoggable(BasicLevel.DEBUG)) { 410 logger.log(BasicLevel.DEBUG, ""); 411 } 412 try { 413 return actConn.getTypeMap(); 414 } catch (SQLException e) { 415 xac.notifyError(e); 416 throw(e); 417 } 418 } 419 420 public void setTypeMap(Map map) 421 throws SQLException { 422 423 if (logger.isLoggable(BasicLevel.DEBUG)) { 424 logger.log(BasicLevel.DEBUG, ""); 425 } 426 try { 427 setTypeMap(map); 428 } catch (SQLException e) { 429 xac.notifyError(e); 430 throw(e); 431 } 432 } 433 434 public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) 435 throws SQLException { 436 437 if (logger.isLoggable(BasicLevel.DEBUG)) { 438 logger.log(BasicLevel.DEBUG, ""); 439 } 440 try { 441 return actConn.prepareStatement(sql, resultSetType, resultSetConcurrency); 442 } catch (SQLException e) { 443 xac.notifyError(e); 444 throw(e); 445 } 446 } 447 448 public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) 449 throws SQLException { 450 451 if (logger.isLoggable(BasicLevel.DEBUG)) { 452 logger.log(BasicLevel.DEBUG, ""); 453 } 454 try { 455 return actConn.prepareCall(sql, resultSetType, resultSetConcurrency); 456 } catch (SQLException e) { 457 xac.notifyError(e); 458 throw(e); 459 } 460 } 461 462 public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) 463 throws SQLException { 464 if (logger.isLoggable(BasicLevel.DEBUG)) { 465 logger.log(BasicLevel.DEBUG, ""); 466 } 467 try { 468 return actConn.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability); 469 } catch (SQLException e) { 470 xac.notifyError(e); 471 throw(e); 472 } 473 } 474 475 public int getHoldability() throws SQLException { 476 if (logger.isLoggable(BasicLevel.DEBUG)) { 477 logger.log(BasicLevel.DEBUG, ""); 478 } 479 try { 480 return actConn.getHoldability(); 481 } catch (SQLException e) { 482 xac.notifyError(e); 483 throw(e); 484 } 485 } 486 487 public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) 488 throws SQLException { 489 490 if (logger.isLoggable(BasicLevel.DEBUG)) { 491 logger.log(BasicLevel.DEBUG, ""); 492 } 493 try { 494 return actConn.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability); 495 } catch (SQLException e) { 496 xac.notifyError(e); 497 throw(e); 498 } 499 } 500 501 public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) 502 throws SQLException { 503 504 if (logger.isLoggable(BasicLevel.DEBUG)) { 505 logger.log(BasicLevel.DEBUG, ""); 506 } 507 try { 508 return actConn.prepareStatement(sql, autoGeneratedKeys); 509 } catch (SQLException e) { 510 xac.notifyError(e); 511 throw(e); 512 } 513 } 514 515 public PreparedStatement prepareStatement(String sql, 516 int resultSetType, 517 int resultSetConcurrency, 518 int resultSetHoldability) 519 throws SQLException { 520 521 if (logger.isLoggable(BasicLevel.DEBUG)) { 522 logger.log(BasicLevel.DEBUG, ""); 523 } 524 525 try { 526 return actConn.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability); 527 } catch (SQLException e) { 528 xac.notifyError(e); 529 throw(e); 530 } 531 } 532 533 public PreparedStatement prepareStatement(String sql, 534 int[] columnIndexes) 535 throws SQLException { 536 if (logger.isLoggable(BasicLevel.DEBUG)) { 537 logger.log(BasicLevel.DEBUG, ""); 538 } 539 540 try { 541 return actConn.prepareStatement(sql, columnIndexes); 542 } catch (SQLException e) { 543 xac.notifyError(e); 544 throw(e); 545 } 546 } 547 548 public PreparedStatement prepareStatement(String sql, 549 String [] columnNames) 550 throws SQLException { 551 if (logger.isLoggable(BasicLevel.DEBUG)) { 552 logger.log(BasicLevel.DEBUG, ""); 553 } 554 555 try { 556 return actConn.prepareStatement(sql, columnNames); 557 } catch (SQLException e) { 558 xac.notifyError(e); 559 throw(e); 560 } 561 } 562 563 public void releaseSavepoint(java.sql.Savepoint savepoint) 564 throws SQLException { 565 if (logger.isLoggable(BasicLevel.DEBUG)) { 566 logger.log(BasicLevel.DEBUG, ""); 567 } 568 569 try { 570 actConn.releaseSavepoint(savepoint); 571 } catch (SQLException e) { 572 xac.notifyError(e); 573 throw(e); 574 } 575 } 576 577 public void rollback(java.sql.Savepoint savepoint) 578 throws SQLException { 579 if (logger.isLoggable(BasicLevel.DEBUG)) { 580 logger.log(BasicLevel.DEBUG, ""); 581 } 582 583 try { 584 actConn.rollback(savepoint); 585 } catch (SQLException e) { 586 xac.notifyError(e); 587 throw(e); 588 } 589 } 590 591 public void setHoldability(int holdability) 592 throws SQLException { 593 if (logger.isLoggable(BasicLevel.DEBUG)) { 594 logger.log(BasicLevel.DEBUG, ""); 595 } 596 597 try { 598 actConn.setHoldability(holdability); 599 } catch (SQLException e) { 600 xac.notifyError(e); 601 throw(e); 602 } 603 } 604 605 public java.sql.Savepoint setSavepoint() 606 throws SQLException { 607 if (logger.isLoggable(BasicLevel.DEBUG)) { 608 logger.log(BasicLevel.DEBUG, ""); 609 } 610 611 try { 612 return actConn.setSavepoint(); 613 } catch (SQLException e) { 614 xac.notifyError(e); 615 throw(e); 616 } 617 } 618 619 public java.sql.Savepoint setSavepoint(String name) 620 throws SQLException { 621 if (logger.isLoggable(BasicLevel.DEBUG)) { 622 logger.log(BasicLevel.DEBUG, ""); 623 } 624 625 try { 626 return actConn.setSavepoint(name); 627 } catch (SQLException e) { 628 xac.notifyError(e); 629 throw(e); 630 } 631 } 632 633 } 634 635 | Popular Tags |