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 } 1025 1026 1034 public void cancel() throws SQLException  1035 { 1036 _underlyingSqlStatement.getStmt().cancel(); 1037 } 1038 1039 1057 public SQLWarning getWarnings() throws SQLException  1058 { 1059 return _underlyingSqlStatement.getStmt().getWarnings(); 1060 } 1061 1062 1071 public void clearWarnings() throws SQLException  1072 { 1073 _underlyingSqlStatement.getStmt().clearWarnings(); 1074 } 1075 1076 1098 public void setCursorName(String name) throws SQLException  1099 { 1100 _underlyingSqlStatement.getStmt().setCursorName(name); 1101 } 1102 1103 1105 1131 public boolean execute(String sql) throws SQLException  1132 { 1133 throw new SQLException ("ps.execute(sql): this method is not implemented by the djeneric driver"); 1134 } 1135 1136 1146 public ResultSet getResultSet() throws SQLException  1147 { 1148 return _underlyingSqlStatement.getStmt().getResultSet(); 1149 } 1150 1151 1162 public int getUpdateCount() throws SQLException  1163 { 1164 throw new SQLException ("ps.getUpdateCount: this method is not implemented by the djeneric driver"); 1165 } 1166 1167 1187 public boolean getMoreResults() throws SQLException  1188 { 1189 return _underlyingSqlStatement.getStmt().getMoreResults(); 1190 } 1191 1192 1194 1213 public void setFetchDirection(int direction) throws SQLException  1214 { 1215 _underlyingSqlStatement.getStmt().setFetchDirection(direction); 1216 } 1217 1218 1233 public int getFetchDirection() throws SQLException  1234 { 1235 return _underlyingSqlStatement.getStmt().getFetchDirection(); 1236 } 1237 1238 1254 public void setFetchSize(int rows) throws SQLException  1255 { 1256 _underlyingSqlStatement.getStmt().setFetchSize(rows); 1257 } 1258 1259 1274 public int getFetchSize() throws SQLException  1275 { 1276 return _underlyingSqlStatement.getStmt().getFetchSize(); 1277 } 1278 1279 1288 public int getResultSetConcurrency() throws SQLException  1289 { 1290 return _underlyingSqlStatement.getStmt().getResultSetConcurrency(); 1291 } 1292 1293 1303 public int getResultSetType() throws SQLException  1304 { 1305 return _underlyingSqlStatement.getStmt().getResultSetType(); 1306 } 1307 1308 1322 public void addBatch(String sql) throws SQLException  1323 { 1324 throw new SQLException ("ps.addBatch(sql): this method is not implemented by the djeneric driver"); 1325 } 1326 1327 1338 public void clearBatch() throws SQLException  1339 { 1340 throw new SQLException ("ps.clearBatch: this method is not implemented by the djeneric driver"); 1341 } 1342 1343 1392 public int[] executeBatch() throws SQLException  1393 { 1394 throw new SQLException ("ps.executeBatch: this method is not implemented by the djeneric driver"); 1395 } 1396 1397 1408 public Connection getConnection() throws SQLException  1409 { 1410 return _connection; 1411 } 1412 1413 1418 public ParameterMetaData getParameterMetaData() throws SQLException  1419 { 1420 throw new SQLException ("ps.getParameterMetaData: this method is not implemented by the djeneric driver"); 1421 } 1422 1423 1428 public void setURL(int arg0, URL arg1) throws SQLException  1429 { 1430 throw new SQLException ("ps.setURL: this method is not implemented by the djeneric driver"); 1431 } 1432 1433 1438 public int executeUpdate(String arg0, int[] arg1) throws SQLException  1439 { 1440 throw new SQLException ("ps.executeUpdate: this method is not implemented by the djeneric driver"); 1441 } 1442 1443 1448 public boolean execute(String arg0, int arg1) throws SQLException  1449 { 1450 throw new SQLException ("ps.execute: this method is not implemented by the djeneric driver"); 1451 } 1452 1453 1458 public boolean execute(String arg0, int[] arg1) throws SQLException  1459 { 1460 throw new SQLException ("ps.execute: this method is not implemented by the djeneric driver"); 1461 } 1462 1463 1468 public boolean execute(String arg0, String [] arg1) throws SQLException  1469 { 1470 throw new SQLException ("ps.execute: this method is not implemented by the djeneric driver"); 1471 } 1472 1473 1478 public int executeUpdate(String arg0, int arg1) throws SQLException  1479 { 1480 throw new SQLException ("ps.executeUpdate: this method is not implemented by the djeneric driver"); 1481 } 1482 1483 1489 public int executeUpdate(String arg0, String [] arg1) throws SQLException  1490 { 1491 throw new SQLException ("ps.executeUpdate: this method is not implemented by the djeneric driver"); 1492 } 1493 1494 1499 public ResultSet getGeneratedKeys() throws SQLException  1500 { 1501 throw new SQLException ("ps.getGeneratedKeys: this method is not implemented by the djeneric driver"); 1502 } 1503 1504 1509 public boolean getMoreResults(int arg0) throws SQLException  1510 { 1511 throw new SQLException ("ps.getMoreResults: this method is not implemented by the djeneric driver"); 1512 } 1513 1514 1519 public int getResultSetHoldability() throws SQLException  1520 { 1521 return 0; 1522 } 1523 1524} | Popular Tags |