1 18 19 package org.webdocwf.util.xml; 20 21 import java.sql.CallableStatement ; 22 import java.sql.Connection ; 23 import java.sql.DatabaseMetaData ; 24 import java.sql.PreparedStatement ; 25 import java.sql.SQLException ; 26 import java.sql.SQLWarning ; 27 import java.sql.Savepoint ; 28 import java.sql.Statement ; 29 import java.util.Enumeration ; 30 import java.util.Hashtable ; 31 import java.util.Map ; 32 import java.util.Properties ; 33 import java.util.ArrayList ; 35 import org.enhydra.xml.SearchElement; 37 38 43 public class XmlConnection implements Connection { 44 45 46 private String path; 47 48 49 private String extension = XmlDriver.DEFAULT_EXTENSION; 50 51 52 53 private ArrayList statements = new ArrayList (); 54 55 56 private String charset = null; 57 58 59 private boolean closed; 60 61 62 private boolean autoCommit = true; 63 64 68 protected XmlConnection(String path) { 69 if(path == null || path.length() == 0) { 71 throw new IllegalArgumentException ( 72 "'path' argument may not be empty or null"); 73 } 74 this.path = path; 75 } 76 77 82 protected XmlConnection(String path, Properties info) { 83 this(path); 84 if(info != null) { 86 if(info.getProperty(XmlDriver.FILE_EXTENSION) != null) { 88 extension = info.getProperty(XmlDriver.FILE_EXTENSION); 89 } 90 91 } 92 } 93 94 109 public Statement createStatement() throws SQLException { 110 XmlStatement statement = new XmlStatement(this); 111 statements.add(statement); 112 return statement; 113 } 114 115 144 public PreparedStatement prepareStatement(String sql) throws SQLException { 145 int index = sql.indexOf("?"); 146 while (index != -1) { 147 sql = sql.substring(0, index) + XmlPreparedStatement.PREPARE_SEPARATOR + 148 sql.substring(index + 1); 149 index = sql.indexOf("?"); 150 } 151 152 XmlPreparedStatement statement = new XmlPreparedStatement(this, sql); 153 statements.add(statement); 154 return statement; 155 156 } 157 158 185 public CallableStatement prepareCall(String sql) throws SQLException { 186 throw new UnsupportedOperationException ( 187 "Connection.prepareCall(String) unsupported"); 188 } 189 190 201 public String nativeSQL(String sql) throws SQLException { 202 throw new UnsupportedOperationException ( 203 "Connection.nativeSQL(String) unsupported"); 204 } 205 206 234 public void setAutoCommit(boolean autoCommit) throws SQLException { 235 this.autoCommit = autoCommit; 236 } 237 238 247 public boolean getAutoCommit() throws SQLException { 248 return this.autoCommit; 249 } 250 251 262 public void commit() throws SQLException { 263 XmlWriter.commit( this.getPath() ); 264 } 265 266 276 public void rollback() throws SQLException { 277 } 278 279 293 public void close() throws SQLException { 294 closed = true; 301 } 302 303 320 public boolean isClosed() throws SQLException { 321 return closed; 322 } 323 324 336 public DatabaseMetaData getMetaData() throws SQLException { 337 return new XmlDatabaseMetaData( this ); 338 } 339 340 351 public void setReadOnly(boolean readOnly) throws SQLException { 352 throw new UnsupportedOperationException ( 353 "Connection.setReadOnly(boolean) unsupported"); 354 } 355 356 364 public boolean isReadOnly() throws SQLException { 365 return false; 366 } 367 368 381 public void setCatalog(String catalog) throws SQLException { 382 } 384 385 392 public String getCatalog() throws SQLException { 393 return null; 394 } 395 396 418 public void setTransactionIsolation(int level) throws SQLException { 419 throw new UnsupportedOperationException ( 420 "Connection.setTransactionIsolation(int) unsupported"); 421 } 422 423 437 public int getTransactionIsolation() throws SQLException { 438 return Connection.TRANSACTION_NONE; 439 } 440 441 462 public SQLWarning getWarnings() throws SQLException { 463 throw new UnsupportedOperationException ( 464 "Connection.getWarnings() unsupported"); 465 } 466 467 475 public void clearWarnings() throws SQLException { 476 throw new UnsupportedOperationException ( 477 "Connection.getWarnings() unsupported"); 478 } 479 480 482 503 public Statement createStatement(int resultSetType, int resultSetConcurrency) 504 throws SQLException { 505 throw new UnsupportedOperationException ( 506 "Connection.createStatement(int, int) unsupported"); 507 } 508 509 533 public PreparedStatement prepareStatement(String sql, int resultSetType, 534 int resultSetConcurrency) throws SQLException { 535 throw new UnsupportedOperationException ( 536 "Connection.prepareStatement(String, int, int) unsupported"); 537 } 538 539 562 public CallableStatement prepareCall(String sql, int resultSetType, 563 int resultSetConcurrency) throws SQLException { 564 throw new UnsupportedOperationException ( 565 "Connection.prepareCall(String, int, int) unsupported"); 566 } 567 568 579 public Map getTypeMap() throws SQLException { 580 throw new UnsupportedOperationException ( 581 "Connection.getTypeMap() unsupported"); 582 } 583 584 597 public void setTypeMap(Map map) throws SQLException { 598 throw new UnsupportedOperationException ( 599 "Connection.setTypeMap(Map) unsupported"); 600 } 601 602 618 public void setHoldability(int holdability) throws SQLException { 619 throw new UnsupportedOperationException ("Connection.setHoldability(int) unsupported"); 620 } 621 622 633 public int getHoldability() throws SQLException { 634 throw new UnsupportedOperationException ("Connection.getHoldability() unsupported"); 635 } 636 637 public Savepoint setSavepoint() throws SQLException { 639 throw new UnsupportedOperationException ("Connection.setSavepoint() unsupported"); 640 } 641 642 public Savepoint setSavepoint(String name) throws SQLException { 643 throw new UnsupportedOperationException ("Connection.setSavepoint(String) unsupported"); 644 } 645 646 public void rollback(Savepoint savepoint) throws SQLException { 647 throw new UnsupportedOperationException ("Connection.rollback(Savepoint) unsupported"); 648 } 649 650 public void releaseSavepoint(Savepoint savepoint) throws SQLException { 651 throw new UnsupportedOperationException ("Connection.releaseSavepoint(Savepoint) unsupported"); 652 } 653 654 655 public Statement createStatement(int resultSetType, 656 int resultSetConcurrency, 657 int resultSetHoldability) throws SQLException { 658 throw new UnsupportedOperationException ("Connection.createStatement(int,int,int) unsupported"); 659 } 660 661 public PreparedStatement prepareStatement(String sql, 662 int resultSetType, 663 int resultSetConcurrency, 664 int resultSetHoldability) throws SQLException { 665 throw new UnsupportedOperationException ("Connection.prepareStatement(String,int,int,int) unsupported"); 666 } 667 668 public CallableStatement prepareCall(String sql, 669 int resultSetType, 670 int resultSetConcurrency, 671 int resultSetHoldability) throws SQLException { 672 throw new UnsupportedOperationException ("Connection.prepareCall(String,int,int,int) unsupported"); 673 } 674 675 public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException { 676 throw new UnsupportedOperationException ("Connection.prepareStatement(String,int) unsupported"); 677 } 678 679 public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException { 680 throw new UnsupportedOperationException ("Connection.prepareStatement(String,int[]) unsupported"); 681 } 682 683 public PreparedStatement prepareStatement(String sql, String [] columnNames) throws SQLException { 684 throw new UnsupportedOperationException ("Connection.prepareStatement(String,String[]) unsupported"); 685 } 686 687 691 695 protected String getPath() { 696 return path; 697 } 698 699 703 protected String getExtension() { 704 if( this.path.endsWith(XmlDriver.DEFAULT_EXTENSION) ) 705 return ""; 706 else 707 return extension; 708 } 709 710 711 715 protected String getCharset() { 716 return charset; 717 } 718 719 723 730 734 } 745 | Popular Tags |