1 30 31 package com.genimen.djeneric.jdbc; 32 33 import java.sql.Connection ; 34 import java.sql.DriverManager ; 35 import java.sql.ResultSet ; 36 import java.sql.SQLException ; 37 import java.sql.SQLWarning ; 38 import java.sql.Statement ; 39 40 import com.genimen.djeneric.repository.exceptions.DjenericException; 41 import com.genimen.djeneric.repository.rdbms.RdbmsSession; 42 import com.genimen.djeneric.repository.rdbms.SqlStatement; 43 44 48 49 public class DjStatement implements Statement 50 { 51 private static final String CLASSNAME = DjStatement.class.getName(); 52 private DjConnection _connection = null; 53 private RdbmsSession _session; 55 56 private String _originalSqlStatement = null; private String _polymorphStatement = null; 59 61 public DjStatement(DjConnection p_con) throws SQLException 62 { 63 this(p_con, 0, ResultSet.CONCUR_READ_ONLY); 64 } 65 66 public DjStatement(DjConnection p_con, int resultSetType, int resultSetConcurrency) throws SQLException 67 { 68 if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) throw new SQLException ( 69 "djeneric jdbc-driver can only handle SELECT statements"); 70 _connection = p_con; 71 try 72 { 73 _session = (RdbmsSession) _connection.getPersistenceManager().createSession(); 74 } 75 catch (DjenericException ex) 76 { 77 throw new SQLException (ex.getMessage()); 78 } 79 } 80 81 public ResultSet executeQuery(String sql) throws SQLException 82 { 83 _originalSqlStatement = sql; 84 _polymorphStatement = _connection.translateSqlToPolymorph(sql); 85 DriverManager.println("original sql : " + _originalSqlStatement); 86 DriverManager.println("translated to sql: " + _polymorphStatement); 87 if (_polymorphStatement.toLowerCase().trim().startsWith("select ") == false) throw new SQLException ( 88 "djeneric jdbc-driver can only handle SELECT statements"); 89 90 try 91 { 92 SqlStatement stat = _session.getInternalSqlStatement(_polymorphStatement); 93 ResultSet rs = stat.executeQuery(); 94 ResultSet rv = DjResultSet.createFromResultSet(rs); 95 stat.close(); 96 return rv; 97 } 98 catch (SQLException e) 99 { 100 throw e; 101 } 102 catch (Exception ee_) 103 { 104 throw new SQLException (ee_.toString()); 105 } 106 } 107 108 public int executeUpdate(String sql) throws SQLException 109 { 110 throw new SQLException ("djeneric jdbc-driver can only handle SELECT statements"); 111 } 112 113 public void close() throws SQLException 114 { 115 _connection.close(this); 116 } 117 118 protected void finalize() 119 { 120 try 121 { 122 super.finalize(); 123 close(); 124 } 125 catch (Throwable e) 126 { 127 } 128 } 129 130 public int getMaxFieldSize() throws SQLException 131 { 132 throw new java.lang.UnsupportedOperationException ("Method getMaxFieldSize() not yet implemented."); 133 } 134 135 public void setMaxFieldSize(int max) throws SQLException 136 { 137 throw new java.lang.UnsupportedOperationException ("Method setMaxFieldSize() not yet implemented."); 138 } 139 140 public int getMaxRows() throws SQLException 141 { 142 throw new java.lang.UnsupportedOperationException ("Method getMaxRows() not yet implemented."); 143 } 144 145 public void setMaxRows(int max) throws SQLException 146 { 147 throw new java.lang.UnsupportedOperationException ("Method setMaxRows() not yet implemented."); 148 } 149 150 public void setEscapeProcessing(boolean enable) throws SQLException 151 { 152 throw new java.lang.UnsupportedOperationException ("Method setEscapeProcessing() not yet implemented."); 153 } 154 155 public int getQueryTimeout() throws SQLException 156 { 157 throw new java.lang.UnsupportedOperationException ("Method getQueryTimeout() not yet implemented."); 158 } 159 160 public void setQueryTimeout(int seconds) throws SQLException 161 { 162 throw new java.lang.UnsupportedOperationException ("Method setQueryTimeout() not yet implemented."); 163 } 164 165 public void cancel() throws SQLException 166 { 167 throw new java.lang.UnsupportedOperationException ("Method cancel() not yet implemented."); 168 } 169 170 public SQLWarning getWarnings() throws SQLException 171 { 172 throw new java.lang.UnsupportedOperationException ("Method getWarnings() not yet implemented."); 173 } 174 175 public void clearWarnings() throws SQLException 176 { 177 throw new java.lang.UnsupportedOperationException ("Method clearWarnings() not yet implemented."); 178 } 179 180 public void setCursorName(String name) throws SQLException 181 { 182 throw new java.lang.UnsupportedOperationException ("Method setCursorName() not yet implemented."); 183 } 184 185 public boolean execute(String sql) throws SQLException 186 { 187 throw new java.lang.UnsupportedOperationException ("Method execute() not yet implemented."); 188 } 189 190 public ResultSet getResultSet() throws SQLException 191 { 192 throw new java.lang.UnsupportedOperationException ("Method getResultSet() not yet implemented."); 193 } 194 195 public int getUpdateCount() throws SQLException 196 { 197 throw new java.lang.UnsupportedOperationException ("Method getUpdateCount() not yet implemented."); 198 } 199 200 public boolean getMoreResults() throws SQLException 201 { 202 throw new java.lang.UnsupportedOperationException ("Method getMoreResults() not yet implemented."); 203 } 204 205 public void setFetchDirection(int direction) throws SQLException 206 { 207 throw new java.lang.UnsupportedOperationException ("Method setFetchDirection() not yet implemented."); 208 } 209 210 public int getFetchDirection() throws SQLException 211 { 212 throw new java.lang.UnsupportedOperationException ("Method getFetchDirection() not yet implemented."); 213 } 214 215 public void setFetchSize(int rows) throws SQLException 216 { 217 throw new java.lang.UnsupportedOperationException ("Method setFetchSize() not yet implemented."); 218 } 219 220 public int getFetchSize() throws SQLException 221 { 222 throw new java.lang.UnsupportedOperationException ("Method getFetchSize() not yet implemented."); 223 } 224 225 public int getResultSetConcurrency() throws SQLException 226 { 227 228 throw new java.lang.UnsupportedOperationException ("Method getResultSetConcurrency() not yet implemented."); 229 } 230 231 public int getResultSetType() throws SQLException 232 { 233 234 throw new java.lang.UnsupportedOperationException ("Method getResultSetType() not yet implemented."); 235 } 236 237 public void addBatch(String sql) throws SQLException 238 { 239 240 throw new java.lang.UnsupportedOperationException ("Method addBatch() not yet implemented."); 241 } 242 243 public void clearBatch() throws SQLException 244 { 245 246 throw new java.lang.UnsupportedOperationException ("Method clearBatch() not yet implemented."); 247 } 248 249 public int[] executeBatch() throws SQLException 250 { 251 252 throw new java.lang.UnsupportedOperationException ("Method executeBatch() not yet implemented."); 253 } 254 255 public Connection getConnection() throws SQLException 256 { 257 258 throw new java.lang.UnsupportedOperationException ("Method getConnection() not yet implemented."); 259 } 260 261 266 public boolean execute(String arg0, int arg1) throws SQLException 267 { 268 return false; 269 } 270 271 276 public boolean execute(String arg0, int[] arg1) throws SQLException 277 { 278 return false; 279 } 280 281 286 public boolean execute(String arg0, String [] arg1) throws SQLException 287 { 288 return false; 289 } 290 291 296 public int executeUpdate(String arg0, int arg1) throws SQLException 297 { 298 return 0; 299 } 300 301 306 public int executeUpdate(String arg0, int[] arg1) throws SQLException 307 { 308 return 0; 309 } 310 311 317 public int executeUpdate(String arg0, String [] arg1) throws SQLException 318 { 319 return 0; 320 } 321 322 327 public ResultSet getGeneratedKeys() throws SQLException 328 { 329 return null; 330 } 331 332 337 public boolean getMoreResults(int arg0) throws SQLException 338 { 339 return false; 340 } 341 342 347 public int getResultSetHoldability() throws SQLException 348 { 349 return 0; 350 } 351 352 } | Popular Tags |