1 25 26 package org.objectweb.easybeans.component.jdbcpool; 27 28 import java.util.Map ; 29 30 import java.sql.CallableStatement ; 31 import java.sql.Connection ; 32 import java.sql.DatabaseMetaData ; 33 import java.sql.PreparedStatement ; 34 import java.sql.SQLException ; 35 import java.sql.SQLWarning ; 36 import java.sql.Savepoint ; 37 import java.sql.Statement ; 38 39 import org.objectweb.easybeans.log.JLog; 40 import org.objectweb.easybeans.log.JLogFactory; 41 42 49 public class JConnection implements Connection { 50 51 54 private static JLog logger = JLogFactory.getLog(JConnection.class); 55 56 59 private Connection physicalConnection = null; 60 61 64 private JManagedConnection xaConnection = null; 65 66 72 public JConnection(final JManagedConnection xaConnection, final Connection physicalConnection) { 73 this.xaConnection = xaConnection; 74 this.physicalConnection = physicalConnection; 75 } 76 77 81 public Connection getConnection() { 82 return physicalConnection; 83 } 84 85 88 public Statement createStatement() throws SQLException { 89 try { 90 return physicalConnection.createStatement(); 91 } catch (SQLException e) { 92 xaConnection.notifyError(e); 93 throw e; 94 } 95 } 96 97 100 public PreparedStatement prepareStatement(final String sql) throws SQLException { 101 try { 102 return xaConnection.prepareStatement(sql); 104 } catch (SQLException e) { 105 xaConnection.notifyError(e); 106 throw e; 107 } 108 } 109 110 113 public CallableStatement prepareCall(final String sql) throws SQLException { 114 try { 115 return physicalConnection.prepareCall(sql); 116 } catch (SQLException e) { 117 xaConnection.notifyError(e); 118 throw e; 119 } 120 } 121 122 125 public String nativeSQL(final String sql) throws SQLException { 126 try { 127 return physicalConnection.nativeSQL(sql); 128 } catch (SQLException e) { 129 xaConnection.notifyError(e); 130 throw e; 131 } 132 } 133 134 138 public boolean isPhysicallyClosed() throws SQLException { 139 return physicalConnection.isClosed(); 140 } 141 142 145 public boolean isClosed() throws SQLException { 146 147 try { 151 return physicalConnection.isClosed(); 152 } catch (SQLException e) { 153 xaConnection.notifyError(e); 154 throw e; 155 } 156 } 157 158 161 public DatabaseMetaData getMetaData() throws SQLException { 162 try { 163 return physicalConnection.getMetaData(); 164 } catch (SQLException e) { 165 xaConnection.notifyError(e); 166 throw e; 167 } 168 } 169 170 173 public void setReadOnly(final boolean readOnly) throws SQLException { 174 try { 175 physicalConnection.setReadOnly(readOnly); 176 } catch (SQLException e) { 177 xaConnection.notifyError(e); 178 throw e; 179 } 180 } 181 182 185 public boolean isReadOnly() throws SQLException { 186 try { 187 return physicalConnection.isReadOnly(); 188 } catch (SQLException e) { 189 xaConnection.notifyError(e); 190 throw e; 191 } 192 } 193 194 197 public void setCatalog(final String catalog) throws SQLException { 198 try { 199 physicalConnection.setCatalog(catalog); 200 } catch (SQLException e) { 201 xaConnection.notifyError(e); 202 throw e; 203 } 204 } 205 206 209 public String getCatalog() throws SQLException { 210 try { 211 return physicalConnection.getCatalog(); 212 } catch (SQLException e) { 213 xaConnection.notifyError(e); 214 throw e; 215 } 216 } 217 218 222 public void close() throws SQLException { 223 xaConnection.notifyClose(); 224 } 225 226 229 public void setTransactionIsolation(final int level) throws SQLException { 230 try { 231 physicalConnection.setTransactionIsolation(level); 232 } catch (SQLException e) { 233 xaConnection.notifyError(e); 234 throw e; 235 } 236 } 237 238 241 public int getTransactionIsolation() throws SQLException { 242 try { 243 return physicalConnection.getTransactionIsolation(); 244 } catch (SQLException e) { 245 xaConnection.notifyError(e); 246 throw e; 247 } 248 } 249 250 253 public SQLWarning getWarnings() throws SQLException { 254 try { 255 return physicalConnection.getWarnings(); 256 } catch (SQLException e) { 257 xaConnection.notifyError(e); 258 throw e; 259 } 260 } 261 262 265 public void clearWarnings() throws SQLException { 266 try { 267 physicalConnection.clearWarnings(); 268 } catch (SQLException e) { 269 xaConnection.notifyError(e); 270 throw e; 271 } 272 } 273 274 278 public void commit() throws SQLException { 279 try { 280 physicalConnection.commit(); 281 } catch (SQLException e) { 282 xaConnection.notifyError(e); 283 throw e; 284 } 285 } 286 287 291 public void rollback() throws SQLException { 292 try { 293 physicalConnection.rollback(); 294 } catch (SQLException e) { 295 xaConnection.notifyError(e); 296 throw e; 297 } 298 } 299 300 304 @SuppressWarnings ("boxing") 305 public void setAutoCommit(final boolean autoCommit) throws SQLException { 306 try { 307 physicalConnection.setAutoCommit(autoCommit); 308 } catch (SQLException e) { 309 logger.error("setAutoCommit( {0} ) failed: ", autoCommit, e); 310 xaConnection.notifyError(e); 311 throw e; 312 } 313 } 314 315 319 public boolean getAutoCommit() throws SQLException { 320 try { 321 return physicalConnection.getAutoCommit(); 322 } catch (SQLException e) { 323 xaConnection.notifyError(e); 324 throw e; 325 } 326 } 327 328 331 public Statement createStatement(final int resultSetType, final int resultSetConcurrency) throws SQLException { 332 try { 333 return physicalConnection.createStatement(resultSetType, resultSetConcurrency); 334 } catch (SQLException e) { 335 xaConnection.notifyError(e); 336 throw e; 337 } 338 } 339 340 343 public Map <String , Class <?>> getTypeMap() throws SQLException { 344 try { 345 return physicalConnection.getTypeMap(); 346 } catch (SQLException e) { 347 xaConnection.notifyError(e); 348 throw e; 349 } 350 } 351 352 355 public void setTypeMap(final Map map) throws SQLException { 356 try { 357 setTypeMap(map); 358 } catch (SQLException e) { 359 xaConnection.notifyError(e); 360 throw e; 361 } 362 } 363 364 367 public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency) 368 throws SQLException { 369 try { 370 return xaConnection.prepareStatement(sql, resultSetType, resultSetConcurrency); 371 } catch (SQLException e) { 372 xaConnection.notifyError(e); 373 throw e; 374 } 375 } 376 377 380 public CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency) 381 throws SQLException { 382 try { 383 return physicalConnection.prepareCall(sql, resultSetType, resultSetConcurrency); 384 } catch (SQLException e) { 385 xaConnection.notifyError(e); 386 throw e; 387 } 388 } 389 390 393 public Statement createStatement(final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability) 394 throws SQLException { 395 try { 396 return physicalConnection.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability); 397 } catch (SQLException e) { 398 xaConnection.notifyError(e); 399 throw e; 400 } 401 } 402 403 406 public int getHoldability() throws SQLException { 407 try { 408 return physicalConnection.getHoldability(); 409 } catch (SQLException e) { 410 xaConnection.notifyError(e); 411 throw e; 412 } 413 } 414 415 418 public CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency, 419 final int resultSetHoldability) throws SQLException { 420 try { 421 return physicalConnection.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability); 422 } catch (SQLException e) { 423 xaConnection.notifyError(e); 424 throw e; 425 } 426 } 427 428 431 public PreparedStatement prepareStatement(final String sql, final int autoGeneratedKeys) throws SQLException { 432 try { 433 return physicalConnection.prepareStatement(sql, autoGeneratedKeys); 434 } catch (SQLException e) { 435 xaConnection.notifyError(e); 436 throw e; 437 } 438 } 439 440 443 public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency, 444 final int resultSetHoldability) throws SQLException { 445 try { 446 return physicalConnection.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability); 447 } catch (SQLException e) { 448 xaConnection.notifyError(e); 449 throw e; 450 } 451 } 452 453 456 public PreparedStatement prepareStatement(final String sql, final int[] columnIndexes) throws SQLException { 457 try { 458 return physicalConnection.prepareStatement(sql, columnIndexes); 459 } catch (SQLException e) { 460 xaConnection.notifyError(e); 461 throw e; 462 } 463 } 464 465 468 public PreparedStatement prepareStatement(final String sql, final String [] columnNames) throws SQLException { 469 try { 470 return physicalConnection.prepareStatement(sql, columnNames); 471 } catch (SQLException e) { 472 xaConnection.notifyError(e); 473 throw e; 474 } 475 } 476 477 480 public void releaseSavepoint(final Savepoint savepoint) throws SQLException { 481 try { 482 physicalConnection.releaseSavepoint(savepoint); 483 } catch (SQLException e) { 484 xaConnection.notifyError(e); 485 throw e; 486 } 487 } 488 489 492 public void rollback(final Savepoint savepoint) throws SQLException { 493 try { 494 physicalConnection.rollback(savepoint); 495 } catch (SQLException e) { 496 xaConnection.notifyError(e); 497 throw e; 498 } 499 } 500 501 504 public void setHoldability(final int holdability) throws SQLException { 505 try { 506 physicalConnection.setHoldability(holdability); 507 } catch (SQLException e) { 508 xaConnection.notifyError(e); 509 throw e; 510 } 511 } 512 513 516 public Savepoint setSavepoint() throws SQLException { 517 try { 518 return physicalConnection.setSavepoint(); 519 } catch (SQLException e) { 520 xaConnection.notifyError(e); 521 throw e; 522 } 523 } 524 525 528 public java.sql.Savepoint setSavepoint(final String name) throws SQLException { 529 try { 530 return physicalConnection.setSavepoint(name); 531 } catch (SQLException e) { 532 xaConnection.notifyError(e); 533 throw e; 534 } 535 } 536 537 } 538 | Popular Tags |