| 1 30 31 package com.genimen.djeneric.jdbc; 32 33 import java.math.BigDecimal ; 34 import java.net.URL ; 35 import java.sql.Array ; 36 import java.sql.Blob ; 37 import java.sql.Clob ; 38 import java.sql.Connection ; 39 import java.sql.DriverManager ; 40 import java.sql.ParameterMetaData ; 41 import java.sql.PreparedStatement ; 42 import java.sql.Ref ; 43 import java.sql.ResultSet ; 44 import java.sql.ResultSetMetaData ; 45 import java.sql.SQLException ; 46 import java.sql.SQLWarning ; 47 import java.util.Calendar ; 48 49 import com.genimen.djeneric.repository.exceptions.DjenericException; 50 import com.genimen.djeneric.repository.rdbms.RdbmsSession; 51 import com.genimen.djeneric.repository.rdbms.SqlStatement; 52 53 57 58 public class DjPreparedStatement implements PreparedStatement  59 { 60 private static final String CLASSNAME = DjPreparedStatement.class.getName(); 61 private DjConnection _connection = null; 62 private SqlStatement _underlyingSqlStatement = null; 63 64 private String _originalSqlStatement = null; private String _polymorphStatement = null; 67 69 public DjPreparedStatement(DjConnection p_con, String p_sql) throws SQLException  70 { 71 this(p_con, p_sql, 0, ResultSet.CONCUR_READ_ONLY); 72 } 73 74 public DjPreparedStatement(DjConnection p_con, String p_sql, int resultSetType, int resultSetConcurrency) 75 throws SQLException  76 { 77 if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) throw new SQLException ( 78 "djeneric jdbc-driver can only handle SELECT statements"); 79 _connection = p_con; 80 _originalSqlStatement = p_sql; 81 _polymorphStatement = _connection.translateSqlToPolymorph(p_sql); 82 DriverManager.println("original sql : " + _originalSqlStatement); 83 DriverManager.println("translated to sql: " + _polymorphStatement); 84 if (_polymorphStatement.toLowerCase().trim().startsWith("select ") == false) throw new SQLException ( 85 "djeneric jdbc-driver can only handle SELECT statements"); 86 87 try 88 { 89 RdbmsSession s = (RdbmsSession) _connection.getPersistenceManager().createSession(); 90 _underlyingSqlStatement = s.getInternalSqlStatement(_polymorphStatement); 91 } 92 catch (DjenericException de) 93 { 94 throw new SQLException (de.toString()); 95 } 96 } 97 98 107 public ResultSet executeQuery() throws SQLException  108 { 109 return _underlyingSqlStatement.executeQuery(); 110 } 111 112 122 public int executeUpdate() throws SQLException  123 { 124 throw new SQLException ("djeneric jdbc-driver can only handle SELECT statements"); 125 } 126 127 140 public void setNull(int parameterIndex, int sqlType) throws SQLException  141 { 142 _underlyingSqlStatement.getStmt().setNull(parameterIndex, sqlType); 143 } 144 145 157 public void setBoolean(int parameterIndex, boolean x) throws SQLException  158 { 159 _underlyingSqlStatement.getStmt().setBoolean(parameterIndex, x); 160 } 161 162 174 public void setByte(int parameterIndex, byte x) throws SQLException  175 { 176 _underlyingSqlStatement.getStmt().setByte(parameterIndex, x); 177 } 178 179 191 public void setShort(int parameterIndex, short x) throws SQLException  192 { 193 _underlyingSqlStatement.getStmt().setShort(parameterIndex, x); 194 } 195 196 208 public void setInt(int parameterIndex, int x) throws SQLException  209 { 210 _underlyingSqlStatement.getStmt().setInt(parameterIndex, x); 211 } 212 213 225 public void setLong(int parameterIndex, long x) throws SQLException  226 { 227 _underlyingSqlStatement.getStmt().setLong(parameterIndex, x); 228 } 229 230 242 public void setFloat(int parameterIndex, float x) throws SQLException  243 { 244 _underlyingSqlStatement.getStmt().setFloat(parameterIndex, x); 245 } 246 247 259 public void setDouble(int parameterIndex, double x) throws SQLException  260 { 261 _underlyingSqlStatement.getStmt().setDouble(parameterIndex, x); 262 } 263 264 276 public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException  277 { 278 _underlyingSqlStatement.getStmt().setBigDecimal(parameterIndex, x); 279 } 280 281 294 public void setString(int parameterIndex, String x) throws SQLException  295 { 296 _underlyingSqlStatement.getStmt().setString(parameterIndex, x); 297 } 298 299 312 public void setBytes(int parameterIndex, byte x[]) throws SQLException  313 { 314 _underlyingSqlStatement.getStmt().setBytes(parameterIndex, x); 315 } 316 317 326 public void setDate(int parameterIndex, java.sql.Date x) throws SQLException  327 { 328 _underlyingSqlStatement.getStmt().setDate(parameterIndex, x); 329 } 330 331 343 public void setTime(int parameterIndex, java.sql.Time x) throws SQLException  344 { 345 _underlyingSqlStatement.getStmt().setTime(parameterIndex, x); 346 } 347 348 360 public void setTimestamp(int parameterIndex, java.sql.Timestamp x) throws SQLException  361 { 362 _underlyingSqlStatement.getStmt().setTimestamp(parameterIndex, x); 363 } 364 365 386 public void setAsciiStream(int parameterIndex, java.io.InputStream x, int length) throws SQLException  387 { 388 _underlyingSqlStatement.getStmt().setAsciiStream(parameterIndex, x, length); 389 } 390 391 416 public void setUnicodeStream(int parameterIndex, java.io.InputStream x, int length) throws SQLException  417 { 418 _underlyingSqlStatement.getStmt().setUnicodeStream(parameterIndex, x, length); 419 } 420 421 441 public void setBinaryStream(int parameterIndex, java.io.InputStream x, int length) throws SQLException  442 { 443 _underlyingSqlStatement.getStmt().setBinaryStream(parameterIndex, x, length); 444 } 445 446 458 public void clearParameters() throws SQLException  459 { 460 _underlyingSqlStatement.getStmt().clearParameters(); 461 } 462 463 466 502 public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException  503 { 504 _underlyingSqlStatement.getStmt().setObject(parameterIndex, x, targetSqlType, scale); 505 } 506 507 522 public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException  523 { 524 _underlyingSqlStatement.getStmt().setObject(parameterIndex, x, targetSqlType); 525 } 526 527 560 public void setObject(int parameterIndex, Object x) throws SQLException  561 { 562 _underlyingSqlStatement.getStmt().setObject(parameterIndex, x); 563 } 564 565 575 public boolean execute() throws SQLException  576 { 577 throw new SQLException ("ps.execute: this method is not implemented by the djeneric driver"); 578 } 579 580 582 593 public void addBatch() throws SQLException  594 { 595 throw new SQLException ("ps.addBatch: this method is not implemented by the djeneric driver"); 596 } 597 598 623 public void setCharacterStream(int parameterIndex, java.io.Reader reader, int length) throws SQLException  624 { 625 _underlyingSqlStatement.getStmt().setCharacterStream(parameterIndex, reader, length); 626 } 627 628 642 public void setRef(int i, Ref x) throws SQLException  643 { 644 _underlyingSqlStatement.getStmt().setRef(i, x); 645 } 646 647 661 public void setBlob(int i, Blob x) throws SQLException  662 { 663 _underlyingSqlStatement.getStmt().setBlob(i, x); 664 } 665 666 680 public void setClob(int i, Clob x) throws SQLException  681 { 682 _underlyingSqlStatement.getStmt().setClob(i, x); 683 } 684 685 700 public void setArray(int i, Array x) throws SQLException  701 { 702 _underlyingSqlStatement.getStmt().setArray(i, x); 703 } 704 705 716 public ResultSetMetaData getMetaData() throws SQLException  717 { 718 719 return null; 720 } 721 722 745 public void setDate(int parameterIndex, java.sql.Date x, Calendar cal) throws SQLException  746 { 747 _underlyingSqlStatement.getStmt().setDate(parameterIndex, x, cal); 748 } 749 750 773 public void setTime(int parameterIndex, java.sql.Time x, Calendar cal) throws SQLException  774 { 775 _underlyingSqlStatement.getStmt().setTime(parameterIndex, x, cal); 776 } 777 778 801 public void setTimestamp(int parameterIndex, java.sql.Timestamp x, Calendar cal) throws SQLException  802 { 803 _underlyingSqlStatement.getStmt().setTimestamp(parameterIndex, x, cal); 804 } 805 806 837 public void setNull(int paramIndex, int sqlType, String typeName) throws SQLException  838 { 839 _underlyingSqlStatement.getStmt().setNull(paramIndex, sqlType, typeName); 840 } 841 842 854 public ResultSet executeQuery(String sql) throws SQLException  855 { 856 throw new SQLException ("ps.executeQuery: this method is not implemented by the djeneric driver"); 857 } 858 859 873 public int executeUpdate(String sql) throws SQLException  874 { 875 throw new SQLException ("ps.executeUpdate: this method is not implemented by the djeneric driver"); 876 } 877 878 893 public void close() throws SQLException  894 { 895 _underlyingSqlStatement.close(); 896 _connection.close(this); 897 } 898 899 protected void finalize() 900 { 901 try 902 { 903 super.finalize(); 904 close(); 905 } 906 catch (Throwable e) 907 { 908 } 909 } 910 911 913 925 public int getMaxFieldSize() throws SQLException  926 { 927 return _underlyingSqlStatement.getStmt().getMaxFieldSize(); 928 } 929 930 944 public void setMaxFieldSize(int max) throws SQLException  945 { 946 _underlyingSqlStatement.getStmt().setMaxFieldSize(max); 947 } 948 949 958 public int getMaxRows() throws SQLException  959 { 960 return _underlyingSqlStatement.getStmt().getMaxRows(); 961 } 962 963 973 public void setMaxRows(int max) throws SQLException  974 { 975 _underlyingSqlStatement.getStmt().setMaxRows(max); 976 } 977 978 992 public void setEscapeProcessing(boolean enable) throws SQLException  993 { 994 _underlyingSqlStatement.getStmt().setEscapeProcessing(enable); 995 } 996 997 1006 public int getQueryTimeout() throws SQLException  1007 { 1008 return _underlyingSqlStatement.getStmt().getQueryTimeout(); 1009 } 1010 1011 1021 public void setQueryTimeout(int seconds) throws SQLException  1022 { 1023 _underlyingSqlStatement.getStmt().setQueryTimeout(seconds); 1024 }
|