1 16 17 18 package org.apache.commons.beanutils; 19 20 21 import java.sql.ResultSet ; 22 import java.sql.SQLException ; 23 import java.util.Iterator ; 24 import java.util.NoSuchElementException ; 25 26 27 36 37 public class ResultSetIterator implements DynaBean, Iterator { 38 39 40 42 43 50 ResultSetIterator(ResultSetDynaClass dynaClass) { 51 52 this.dynaClass = dynaClass; 53 54 } 55 56 57 59 60 61 65 protected boolean current = false; 66 67 68 71 protected ResultSetDynaClass dynaClass = null; 72 73 74 78 protected boolean eof = false; 79 80 81 83 84 94 public boolean contains(String name, String key) { 95 96 throw new UnsupportedOperationException 97 ("FIXME - mapped properties not currently supported"); 98 99 } 100 101 102 110 public Object get(String name) { 111 112 if (dynaClass.getDynaProperty(name) == null) { 113 throw new IllegalArgumentException (name); 114 } 115 try { 116 return (dynaClass.getResultSet().getObject(name)); 117 } catch (SQLException e) { 118 throw new RuntimeException 119 ("get(" + name + "): SQLException: " + e); 120 } 121 122 } 123 124 125 140 public Object get(String name, int index) { 141 142 throw new UnsupportedOperationException 143 ("FIXME - indexed properties not currently supported"); 144 145 } 146 147 148 160 public Object get(String name, String key) { 161 162 throw new UnsupportedOperationException 163 ("FIXME - mapped properties not currently supported"); 164 165 } 166 167 168 172 public DynaClass getDynaClass() { 173 174 return (this.dynaClass); 175 176 } 177 178 179 190 public void remove(String name, String key) { 191 192 throw new UnsupportedOperationException 193 ("FIXME - mapped operations not currently supported"); 194 195 } 196 197 198 211 public void set(String name, Object value) { 212 213 if (dynaClass.getDynaProperty(name) == null) { 214 throw new IllegalArgumentException (name); 215 } 216 try { 217 dynaClass.getResultSet().updateObject(name, value); 218 } catch (SQLException e) { 219 throw new RuntimeException 220 ("set(" + name + "): SQLException: " + e); 221 } 222 223 } 224 225 226 242 public void set(String name, int index, Object value) { 243 244 throw new UnsupportedOperationException 245 ("FIXME - indexed properties not currently supported"); 246 247 } 248 249 250 264 public void set(String name, String key, Object value) { 265 266 throw new UnsupportedOperationException 267 ("FIXME - mapped properties not currently supported"); 268 269 } 270 271 272 274 275 278 public boolean hasNext() { 279 280 try { 281 advance(); 282 return (!eof); 283 } catch (SQLException e) { 284 throw new RuntimeException ("hasNext(): SQLException: " + e); 285 } 286 287 } 288 289 290 293 public Object next() { 294 295 try { 296 advance(); 297 if (eof) { 298 throw new NoSuchElementException (); 299 } 300 current = false; 301 return (this); 302 } catch (SQLException e) { 303 throw new RuntimeException ("next(): SQLException: " + e); 304 } 305 306 } 307 308 309 313 public void remove() { 314 315 throw new UnsupportedOperationException ("remove()"); 316 317 } 318 319 320 322 323 329 protected void advance() throws SQLException { 330 331 if (!current && !eof) { 332 if (dynaClass.getResultSet().next()) { 333 current = true; 334 eof = false; 335 } else { 336 current = false; 337 eof = true; 338 } 339 } 340 341 } 342 343 344 } 345 | Popular Tags |