1 package com.quadcap.jdbc; 2 3 40 41 import java.io.IOException ; 42 43 import java.util.Map ; 44 45 import java.sql.CallableStatement ; 46 import java.sql.ResultSet ; 47 import java.sql.Savepoint ; 49 import java.sql.SQLException ; 51 import java.sql.SQLWarning ; 52 53 import com.quadcap.sql.Database; 54 import com.quadcap.sql.DbException; 55 import com.quadcap.sql.Session; 56 57 import com.quadcap.util.ConfigNumber; 58 import com.quadcap.util.Debug; 59 import com.quadcap.util.Util; 60 61 69 public class Connection implements java.sql.Connection { 70 82 83 static final ConfigNumber trace = 85 ConfigNumber.find("qed.trace.Connection", "0"); 86 88 Database db; 89 com.quadcap.sql.Connection qConn = null; 90 boolean closed = false; 91 Map typeMap = null; 92 93 102 public Connection(Database db, String auth, String passwd) 103 throws SQLException 104 { 105 this.db = db; 106 if (auth == null) auth = ""; 107 this.qConn = new com.quadcap.sql.Connection(db, auth.toUpperCase(), 108 passwd); 109 if (trace.bit(0)) { 111 Debug.println("Connection.init(" + qConn + ")"); 112 } 113 } 115 116 122 public Database getDatabase() { 123 return db; 124 } 125 126 132 public final com.quadcap.sql.Connection getConnection() { 133 return qConn; 134 } 135 136 140 145 public void clearWarnings() { 146 } 147 148 157 public void close() throws SQLException { 158 if (trace.bit(0)) { 160 Debug.println("Connection[" + qConn + "].close()"); 161 } 162 closed = true; 164 try { 165 if (qConn != null) qConn.close(); 166 } catch (IOException e) { 167 throw DbException.wrapThrowable(e); 168 } finally { 169 qConn = null; 170 } 171 } 172 173 176 public void finalize() throws Throwable { 177 if (!closed) { 178 try { 179 close(); 180 } catch (Throwable t) {} 181 } 182 super.finalize(); 183 } 184 185 193 public void commit() throws SQLException { 194 if (trace.bit(1)) { 196 Debug.println("Connection.commit()"); 197 } 198 if (closed) throw new SQLException ("Connection closed", "08003"); 200 try { 201 qConn.endTransaction(); 202 } catch (IOException e) { 203 throw DbException.wrapThrowable(e); 204 } 205 } 206 207 214 public java.sql.Statement createStatement() throws SQLException { 215 if (closed) throw new SQLException ("Connection closed", "08003"); 216 try { 217 return new Statement(this); 218 } catch (IOException e) { 219 throw DbException.wrapThrowable(e); 220 } 221 } 222 223 230 public boolean getAutoCommit() throws SQLException { 231 if (closed) throw new SQLException ("Connection closed", "08003"); 232 return qConn.getAutoCommit(); 233 } 234 235 241 public String getCatalog() { 242 return null; 243 } 244 245 251 DatabaseMetaData dbm = null; 252 public java.sql.DatabaseMetaData getMetaData() throws SQLException { 253 try { 254 if (dbm == null) { 255 dbm = new DatabaseMetaData(this); 256 } 257 } catch (IOException e) { 258 throw DbException.wrapThrowable(e); 259 } 260 return dbm; 261 } 262 263 269 public int getTransactionIsolation() { 270 return TRANSACTION_SERIALIZABLE; 271 } 272 273 279 public SQLWarning getWarnings() { 280 return null; 281 } 282 283 288 public boolean isClosed() { 289 return closed; 290 } 291 292 299 public boolean isReadOnly() { 300 return false; 301 } 302 303 313 public String nativeSQL(String stmt) { 314 return stmt; 315 } 316 317 325 public CallableStatement prepareCall(String sql) throws SQLException { 326 throw new SQLException ("Not implemented"); 327 } 328 329 340 public CallableStatement prepareCall(String sql, int resultType, 341 int resultSetConcurrency) 342 throws SQLException 343 { 344 throw new SQLException ("Not implemented"); 345 } 346 347 360 public java.sql.PreparedStatement prepareStatement(String sql) 361 throws SQLException 362 { 363 if (closed) throw new SQLException ("Connection closed", "08003"); 364 try { 365 return new PreparedStatement(this, sql); 366 } catch (IOException e) { 367 throw DbException.wrapThrowable(e); 368 } 369 } 370 371 387 public java.sql.PreparedStatement prepareStatement(String sql, 388 int resultType, 389 int resultSetConcurrency) 390 throws SQLException 391 { 392 if (closed) throw new SQLException ("Connection closed", "08003"); 393 try { 394 return new PreparedStatement(this, sql, resultType, 395 resultSetConcurrency); 396 } catch (IOException e) { 397 throw DbException.wrapThrowable(e); 398 } 399 } 400 401 409 public void rollback() throws SQLException { 410 if (trace.bit(1)) { 412 Debug.println("Connection.rollback()"); 413 } 414 if (closed) { 416 throw new SQLException ("Connection closed", "08003"); 417 } 418 try { 419 qConn.rollbackTransaction(); 420 } catch (IOException e) { 421 throw DbException.wrapThrowable(e); 422 } 423 } 424 425 430 public void setAutoCommit(boolean autoCommit) throws SQLException { 431 if (trace.bit(1)) { 433 Debug.println("Connection.setAutoCommit(" + autoCommit + ")"); 434 } 435 if (closed) throw new SQLException ("Connection closed", "08003"); 437 qConn.setAutoCommit(autoCommit); 438 } 439 440 446 public void setCatalog(String catalog) throws SQLException { 447 throw new SQLException ("Not implemented"); 448 } 449 450 458 public void setReadOnly(boolean readOnly) throws SQLException { 459 if (readOnly) { 460 throw new SQLException ("Read-only connections not supported"); 461 } 462 } 463 464 473 public void setTransactionIsolation(int trans) throws SQLException { 474 if (trans != TRANSACTION_SERIALIZABLE) { 475 throw new SQLException ("Transaction isolation " + trans + 476 " not supported"); 477 } 478 479 } 480 481 489 public void setTypeMap(Map map) throws SQLException { 490 this.typeMap = map; 491 } 492 493 500 public Map getTypeMap() throws SQLException { 501 return typeMap; 502 } 503 504 514 public java.sql.Statement createStatement(int resultType, 515 int resultSetConcurrency) 516 throws SQLException 517 { 518 if (closed) throw new SQLException ("Connection closed", "08003"); 519 try { 520 return new Statement(this, resultType, resultSetConcurrency); 521 } catch (IOException e) { 522 throw DbException.wrapThrowable(e); 523 } 524 } 525 526 528 529 531 549 public void setHoldability(int holdability) throws SQLException { 550 if (holdability != ResultSet.CLOSE_CURSORS_AT_COMMIT) { 551 throw new SQLException ("Not implemented"); 552 } 553 } 554 555 569 public int getHoldability() throws SQLException { 570 return ResultSet.CLOSE_CURSORS_AT_COMMIT; 571 } 572 573 586 public Savepoint setSavepoint() throws SQLException { 587 throw new SQLException ("Not implemented"); 588 } 589 590 604 public Savepoint setSavepoint(String name) throws SQLException { 605 throw new SQLException ("Not implemented"); 606 } 607 608 625 public void rollback(Savepoint savepoint) throws SQLException { 626 throw new SQLException ("Not implemented"); 627 } 628 629 642 public void releaseSavepoint(Savepoint savepoint) throws SQLException { 643 throw new SQLException ("Not implemented"); 644 } 645 646 676 public java.sql.Statement createStatement(int resultSetType, 677 int resultSetConcurrency, 678 int resultSetHoldability) 679 throws SQLException 680 { 681 setHoldability(resultSetHoldability); 682 return createStatement(resultSetType, resultSetConcurrency); 683 } 684 685 720 public 721 java.sql.PreparedStatement prepareStatement(String sql, int resultSetType, 722 int resultSetConcurrency, 723 int resultSetHoldability) 724 throws SQLException { 725 setHoldability(resultSetHoldability); 726 return prepareStatement(sql, resultSetType, resultSetConcurrency); 727 } 728 729 761 public 762 CallableStatement prepareCall(String sql, int resultSetType, 763 int resultSetConcurrency, 764 int resultSetHoldability) 765 throws SQLException 766 { 767 setHoldability(resultSetHoldability); 768 return prepareCall(sql, resultSetType, resultSetConcurrency); 769 } 770 771 810 public 811 java.sql.PreparedStatement prepareStatement(String sql, 812 int autoGeneratedKeys) 813 throws SQLException 814 { 815 if (autoGeneratedKeys == Statement.RETURN_GENERATED_KEYS) { 816 throw new SQLException ("RETURN_GENERATED_KEYS not implemented"); 817 } 818 return prepareStatement(sql); 819 } 820 821 860 public 861 java.sql.PreparedStatement prepareStatement(String sql, 862 int columnIndexes[]) 863 throws SQLException 864 { 865 throw new SQLException ("RETURN_GENERATED_KEYS not implemented"); 866 } 867 868 907 public 908 java.sql.PreparedStatement prepareStatement(String sql, 909 String columnNames[]) 910 throws SQLException 911 { 912 throw new SQLException ("RETURN_GENERATED_KEYS not implemented"); 913 } 914 } 916 | Popular Tags |