1 21 package net.sf.hajdbc.sql; 22 23 import java.sql.DatabaseMetaData ; 24 import java.sql.SQLException ; 25 import java.sql.SQLWarning ; 26 import java.util.Map ; 27 28 import net.sf.hajdbc.Database; 29 import net.sf.hajdbc.Operation; 30 31 37 public class Connection<P> extends SQLObject<java.sql.Connection , P> implements java.sql.Connection 38 { 39 private FileSupport fileSupport; 40 41 48 public Connection(SQLObject<P, ?> object, Operation<P, java.sql.Connection > operation, FileSupport fileSupport) throws java.sql.SQLException 49 { 50 super(object, operation, object.getDatabaseCluster().getNonTransactionalExecutor(), null); 51 52 this.fileSupport = fileSupport; 53 } 54 55 58 public void clearWarnings() throws SQLException 59 { 60 Operation<java.sql.Connection , Void > operation = new Operation<java.sql.Connection , Void >() 61 { 62 public Void execute(Database database, java.sql.Connection connection) throws SQLException 63 { 64 connection.clearWarnings(); 65 66 return null; 67 } 68 }; 69 70 this.executeWriteToDriver(operation); 71 } 72 73 76 public void close() throws SQLException 77 { 78 Operation<java.sql.Connection , Void > operation = new Operation<java.sql.Connection , Void >() 79 { 80 public Void execute(Database database, java.sql.Connection connection) throws SQLException 81 { 82 connection.close(); 83 84 return null; 85 } 86 }; 87 88 this.executeNonTransactionalWriteToDatabase(operation); 89 90 this.fileSupport.close(); 91 } 92 93 96 public void commit() throws SQLException 97 { 98 Operation<java.sql.Connection , Void > operation = new Operation<java.sql.Connection , Void >() 99 { 100 public Void execute(Database database, java.sql.Connection connection) throws SQLException 101 { 102 connection.commit(); 103 104 return null; 105 } 106 }; 107 108 this.executeNonTransactionalWriteToDatabase(operation); 109 } 110 111 114 public java.sql.Statement createStatement() throws SQLException 115 { 116 Operation<java.sql.Connection , java.sql.Statement > operation = new Operation<java.sql.Connection , java.sql.Statement >() 117 { 118 public java.sql.Statement execute(Database database, java.sql.Connection connection) throws SQLException 119 { 120 return connection.createStatement(); 121 } 122 }; 123 124 return this.isReadOnly() ? this.executeReadFromDriver(operation) : new Statement<java.sql.Statement >(this, operation); 125 } 126 127 130 public java.sql.Statement createStatement(final int resultSetType, final int resultSetConcurrency) throws SQLException 131 { 132 Operation<java.sql.Connection , java.sql.Statement > operation = new Operation<java.sql.Connection , java.sql.Statement >() 133 { 134 public java.sql.Statement execute(Database database, java.sql.Connection connection) throws SQLException 135 { 136 return connection.createStatement(resultSetType, resultSetConcurrency); 137 } 138 }; 139 140 return this.isReadOnly() ? this.executeReadFromDriver(operation) : new Statement<java.sql.Statement >(this, operation); 141 } 142 143 146 public java.sql.Statement createStatement(final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability) throws SQLException 147 { 148 Operation<java.sql.Connection , java.sql.Statement > operation = new Operation<java.sql.Connection , java.sql.Statement >() 149 { 150 public java.sql.Statement execute(Database database, java.sql.Connection connection) throws SQLException 151 { 152 return connection.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability); 153 } 154 }; 155 156 return this.isReadOnly() ? this.executeReadFromDriver(operation) : new Statement<java.sql.Statement >(this, operation); 157 } 158 159 162 public boolean getAutoCommit() throws SQLException 163 { 164 Operation<java.sql.Connection , Boolean > operation = new Operation<java.sql.Connection , Boolean >() 165 { 166 public Boolean execute(Database database, java.sql.Connection connection) throws SQLException 167 { 168 return connection.getAutoCommit(); 169 } 170 }; 171 172 return this.executeReadFromDriver(operation); 173 } 174 175 178 public String getCatalog() throws SQLException 179 { 180 Operation<java.sql.Connection , String > operation = new Operation<java.sql.Connection , String >() 181 { 182 public String execute(Database database, java.sql.Connection connection) throws SQLException 183 { 184 return connection.getCatalog(); 185 } 186 }; 187 188 return this.executeReadFromDatabase(operation); 189 } 190 191 194 public int getHoldability() throws SQLException 195 { 196 Operation<java.sql.Connection , Integer > operation = new Operation<java.sql.Connection , Integer >() 197 { 198 public Integer execute(Database database, java.sql.Connection connection) throws SQLException 199 { 200 return connection.getHoldability(); 201 } 202 }; 203 204 return this.executeReadFromDriver(operation); 205 } 206 207 210 public DatabaseMetaData getMetaData() throws SQLException 211 { 212 Operation<java.sql.Connection , DatabaseMetaData > operation = new Operation<java.sql.Connection , DatabaseMetaData >() 213 { 214 public DatabaseMetaData execute(Database database, java.sql.Connection connection) throws SQLException 215 { 216 return connection.getMetaData(); 217 } 218 }; 219 220 return this.executeReadFromDatabase(operation); 221 } 222 223 226 public int getTransactionIsolation() throws SQLException 227 { 228 Operation<java.sql.Connection , Integer > operation = new Operation<java.sql.Connection , Integer >() 229 { 230 public Integer execute(Database database, java.sql.Connection connection) throws SQLException 231 { 232 return connection.getTransactionIsolation(); 233 } 234 }; 235 236 return this.executeReadFromDatabase(operation); 237 } 238 239 242 public Map <String , Class <?>> getTypeMap() throws SQLException 243 { 244 Operation<java.sql.Connection , Map <String , Class <?>>> operation = new Operation<java.sql.Connection , Map <String , Class <?>>>() 245 { 246 public Map <String , Class <?>> execute(Database database, java.sql.Connection connection) throws SQLException 247 { 248 return connection.getTypeMap(); 249 } 250 }; 251 252 return this.executeReadFromDriver(operation); 253 } 254 255 258 public SQLWarning getWarnings() throws SQLException 259 { 260 Operation<java.sql.Connection , SQLWarning > operation = new Operation<java.sql.Connection , SQLWarning >() 261 { 262 public SQLWarning execute(Database database, java.sql.Connection connection) throws SQLException 263 { 264 return connection.getWarnings(); 265 } 266 }; 267 268 return this.executeReadFromDriver(operation); 269 } 270 271 274 public boolean isClosed() throws SQLException 275 { 276 Operation<java.sql.Connection , Boolean > operation = new Operation<java.sql.Connection , Boolean >() 277 { 278 public Boolean execute(Database database, java.sql.Connection connection) throws SQLException 279 { 280 return connection.isClosed(); 281 } 282 }; 283 284 return this.executeReadFromDriver(operation); 285 } 286 287 290 public boolean isReadOnly() throws SQLException 291 { 292 Operation<java.sql.Connection , Boolean > operation = new Operation<java.sql.Connection , Boolean >() 293 { 294 public Boolean execute(Database database, java.sql.Connection connection) throws SQLException 295 { 296 return connection.isReadOnly(); 297 } 298 }; 299 300 return this.executeReadFromDriver(operation); 301 } 302 303 306 public String nativeSQL(final String sql) throws SQLException 307 { 308 Operation<java.sql.Connection , String > operation = new Operation<java.sql.Connection , String >() 309 { 310 public String execute(Database database, java.sql.Connection connection) throws SQLException 311 { 312 return connection.nativeSQL(sql); 313 } 314 }; 315 316 return this.executeReadFromDriver(operation); 317 } 318 319 322 public java.sql.CallableStatement prepareCall(final String sql) throws SQLException 323 { 324 Operation<java.sql.Connection , java.sql.CallableStatement > operation = new Operation<java.sql.Connection , java.sql.CallableStatement >() 325 { 326 public java.sql.CallableStatement execute(Database database, java.sql.Connection connection) throws SQLException 327 { 328 return connection.prepareCall(sql); 329 } 330 }; 331 332 return this.isReadOnly() ? this.executeReadFromDatabase(operation) : new CallableStatement(this, operation, sql); 333 } 334 335 338 public java.sql.CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency) throws SQLException 339 { 340 Operation<java.sql.Connection , java.sql.CallableStatement > operation = new Operation<java.sql.Connection , java.sql.CallableStatement >() 341 { 342 public java.sql.CallableStatement execute(Database database, java.sql.Connection connection) throws SQLException 343 { 344 return connection.prepareCall(sql, resultSetType, resultSetConcurrency); 345 } 346 }; 347 348 return this.isReadOnly() ? this.executeReadFromDatabase(operation) : new CallableStatement(this, operation, sql); 349 } 350 351 354 public java.sql.CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability) throws SQLException 355 { 356 Operation<java.sql.Connection , java.sql.CallableStatement > operation = new Operation<java.sql.Connection , java.sql.CallableStatement >() 357 { 358 public java.sql.CallableStatement execute(Database database, java.sql.Connection connection) throws SQLException 359 { 360 return connection.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability); 361 } 362 }; 363 364 return this.isReadOnly() ? this.executeReadFromDatabase(operation) : new CallableStatement(this, operation, sql); 365 } 366 367 370 public java.sql.PreparedStatement prepareStatement(final String sql) throws SQLException 371 { 372 Operation<java.sql.Connection , java.sql.PreparedStatement > operation = new Operation<java.sql.Connection , java.sql.PreparedStatement >() 373 { 374 public java.sql.PreparedStatement execute(Database database, java.sql.Connection connection) throws SQLException 375 { 376 return connection.prepareStatement(sql); 377 } 378 }; 379 380 return this.isReadOnly() ? this.executeReadFromDatabase(operation) : new PreparedStatement<java.sql.PreparedStatement >(this, operation, sql); 381 } 382 383 386 public java.sql.PreparedStatement prepareStatement(final String sql, final int autoGeneratedKeys) throws SQLException 387 { 388 Operation<java.sql.Connection , java.sql.PreparedStatement > operation = new Operation<java.sql.Connection , java.sql.PreparedStatement >() 389 { 390 public java.sql.PreparedStatement execute(Database database, java.sql.Connection connection) throws SQLException 391 { 392 return connection.prepareStatement(sql, autoGeneratedKeys); 393 } 394 }; 395 396 return this.isReadOnly() ? this.executeReadFromDatabase(operation) : new PreparedStatement<java.sql.PreparedStatement >(this, operation, sql); 397 } 398 399 402 public java.sql.PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency) throws SQLException 403 { 404 Operation<java.sql.Connection , java.sql.PreparedStatement > operation = new Operation<java.sql.Connection , java.sql.PreparedStatement >() 405 { 406 public java.sql.PreparedStatement execute(Database database, java.sql.Connection connection) throws SQLException 407 { 408 return connection.prepareStatement(sql, resultSetType, resultSetConcurrency); 409 } 410 }; 411 412 return this.isReadOnly() ? this.executeReadFromDatabase(operation) : new PreparedStatement<java.sql.PreparedStatement >(this, operation, sql); 413 } 414 415 418 public java.sql.PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability) throws SQLException 419 { 420 Operation<java.sql.Connection , java.sql.PreparedStatement > operation = new Operation<java.sql.Connection , java.sql.PreparedStatement >() 421 { 422 public java.sql.PreparedStatement execute(Database database, java.sql.Connection connection) throws SQLException 423 { 424 return connection.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability); 425 } 426 }; 427 428 return this.isReadOnly() ? this.executeReadFromDatabase(operation) : new PreparedStatement<java.sql.PreparedStatement >(this, operation, sql); 429 } 430 431 434 public java.sql.PreparedStatement prepareStatement(final String sql, final int[] columnIndexes) throws SQLException 435 { 436 Operation<java.sql.Connection , java.sql.PreparedStatement > operation = new Operation<java.sql.Connection , java.sql.PreparedStatement >() 437 { 438 public java.sql.PreparedStatement execute(Database database, java.sql.Connection connection) throws SQLException 439 { 440 return connection.prepareStatement(sql, columnIndexes); 441 } 442 }; 443 444 return this.isReadOnly() ? this.executeReadFromDatabase(operation) : new PreparedStatement<java.sql.PreparedStatement >(this, operation, sql); 445 } 446 447 450 public java.sql.PreparedStatement prepareStatement(final String sql, final String [] columnNames) throws SQLException 451 { 452 Operation<java.sql.Connection , java.sql.PreparedStatement > operation = new Operation<java.sql.Connection , java.sql.PreparedStatement >() 453 { 454 public java.sql.PreparedStatement execute(Database database, java.sql.Connection connection) throws SQLException 455 { 456 return connection.prepareStatement(sql, columnNames); 457 } 458 }; 459 460 return this.isReadOnly() ? this.executeReadFromDatabase(operation) : new PreparedStatement<java.sql.PreparedStatement >(this, operation, sql); 461 } 462 463 466 public void releaseSavepoint(final java.sql.Savepoint savepoint) throws SQLException 467 { 468 Operation<java.sql.Connection , Void > operation = new Operation<java.sql.Connection , Void >() 469 { 470 public Void execute(Database database, java.sql.Connection connection) throws SQLException 471 { 472 connection.releaseSavepoint(Savepoint.class.cast(savepoint)); 473 474 return null; 475 } 476 }; 477 478 this.executeTransactionalWriteToDatabase(operation); 479 } 480 481 484 public void rollback() throws SQLException 485 { 486 Operation<java.sql.Connection , Void > operation = new Operation<java.sql.Connection , Void >() 487 { 488 public Void execute(Database database, java.sql.Connection connection) throws SQLException 489 { 490 connection.rollback(); 491 492 return null; 493 } 494 }; 495 496 this.executeNonTransactionalWriteToDatabase(operation); 497 } 498 499 502 public void rollback(final java.sql.Savepoint savepoint) throws SQLException 503 { 504 Operation<java.sql.Connection , Void > operation = new Operation<java.sql.Connection , Void >() 505 { 506 public Void execute(Database database, java.sql.Connection connection) throws SQLException 507 { 508 connection.rollback(Savepoint.class.cast(savepoint)); 509 510 return null; 511 } 512 }; 513 514 this.executeTransactionalWriteToDatabase(operation); 515 } 516 517 520 public void setAutoCommit(final boolean autoCommit) throws SQLException 521 { 522 Operation<java.sql.Connection , Void > operation = new Operation<java.sql.Connection , Void >() 523 { 524 public Void execute(Database database, java.sql.Connection connection) throws SQLException 525 { 526 connection.setAutoCommit(autoCommit); 527 528 return null; 529 } 530 }; 531 532 this.executeNonTransactionalWriteToDatabase(operation); 533 534 this.record(operation); 535 } 536 537 540 public void setCatalog(final String catalog) throws SQLException 541 { 542 Operation<java.sql.Connection , Void > operation = new Operation<java.sql.Connection , Void >() 543 { 544 public Void execute(Database database, java.sql.Connection connection) throws SQLException 545 { 546 connection.setCatalog(catalog); 547 548 return null; 549 } 550 }; 551 552 this.executeNonTransactionalWriteToDatabase(operation); 553 554 this.record(operation); 555 } 556 557 560 public void setHoldability(final int holdability) throws SQLException 561 { 562 Operation<java.sql.Connection , Void > operation = new Operation<java.sql.Connection , Void >() 563 { 564 public Void execute(Database database, java.sql.Connection connection) throws SQLException 565 { 566 connection.setHoldability(holdability); 567 568 return null; 569 } 570 }; 571 572 this.executeWriteToDriver(operation); 573 } 574 575 578 public void setReadOnly(final boolean readOnly) throws SQLException 579 { 580 Operation<java.sql.Connection , Void > operation = new Operation<java.sql.Connection , Void >() 581 { 582 public Void execute(Database database, java.sql.Connection connection) throws SQLException 583 { 584 connection.setReadOnly(readOnly); 585 586 return null; 587 } 588 }; 589 590 this.executeWriteToDriver(operation); 591 } 592 593 596 public java.sql.Savepoint setSavepoint() throws SQLException 597 { 598 Operation<java.sql.Connection , java.sql.Savepoint > operation = new Operation<java.sql.Connection , java.sql.Savepoint >() 599 { 600 public java.sql.Savepoint execute(Database database, java.sql.Connection connection) throws SQLException 601 { 602 return connection.setSavepoint(); 603 } 604 }; 605 606 return new Savepoint(this, operation); 607 } 608 609 612 public java.sql.Savepoint setSavepoint(final String name) throws SQLException 613 { 614 Operation<java.sql.Connection , java.sql.Savepoint > operation = new Operation<java.sql.Connection , java.sql.Savepoint >() 615 { 616 public java.sql.Savepoint execute(Database database, java.sql.Connection connection) throws SQLException 617 { 618 return connection.setSavepoint(name); 619 } 620 }; 621 622 return new Savepoint(this, operation); 623 } 624 625 628 public void setTransactionIsolation(final int transactionIsolation) throws SQLException 629 { 630 Operation<java.sql.Connection , Void > operation = new Operation<java.sql.Connection , Void >() 631 { 632 public Void execute(Database database, java.sql.Connection connection) throws SQLException 633 { 634 connection.setTransactionIsolation(transactionIsolation); 635 636 return null; 637 } 638 }; 639 640 this.executeNonTransactionalWriteToDatabase(operation); 641 642 this.record(operation); 643 } 644 645 648 public void setTypeMap(final Map <String , Class <?>> map) throws SQLException 649 { 650 Operation<java.sql.Connection , Void > operation = new Operation<java.sql.Connection , Void >() 651 { 652 public Void execute(Database database, java.sql.Connection connection) throws SQLException 653 { 654 connection.setTypeMap(map); 655 656 return null; 657 } 658 }; 659 660 this.executeWriteToDriver(operation); 661 } 662 663 666 public FileSupport getFileSupport() 667 { 668 return this.fileSupport; 669 } 670 671 674 @Override 675 protected void close(java.sql.Connection connection) throws SQLException 676 { 677 connection.close(); 678 } 679 } 680 | Popular Tags |