1 61 62 63 package net.mlw.vlh.adapter.jdbc.dynabean.fix; 64 65 66 import java.sql.SQLException ; 67 import java.util.Iterator ; 68 import java.util.NoSuchElementException ; 69 70 import org.apache.commons.beanutils.DynaBean; 71 import org.apache.commons.beanutils.DynaClass; 72 73 74 83 84 public class ResultSetIterator implements DynaBean, Iterator { 85 86 87 89 90 97 ResultSetIterator(ResultSetDynaClass dynaClass) { 98 99 this.dynaClass = dynaClass; 100 101 } 102 103 104 106 107 108 112 protected boolean current = false; 113 114 115 118 protected ResultSetDynaClass dynaClass = null; 119 120 121 125 protected boolean eof = false; 126 127 128 130 131 141 public boolean contains(String name, String key) { 142 143 throw new UnsupportedOperationException 144 ("FIXME - mapped properties not currently supported"); 145 146 } 147 148 149 157 public Object get(String name) { 158 159 if (dynaClass.getDynaProperty(name) == null) { 160 throw new IllegalArgumentException (name); 161 } 162 try { 163 return (dynaClass.getResultSet().getObject(name)); 164 } catch (SQLException e) { 165 return null; 166 } 167 168 } 169 170 171 186 public Object get(String name, int index) { 187 188 throw new UnsupportedOperationException 189 ("FIXME - indexed properties not currently supported"); 190 191 } 192 193 194 206 public Object get(String name, String key) { 207 208 throw new UnsupportedOperationException 209 ("FIXME - mapped properties not currently supported"); 210 211 } 212 213 214 218 public DynaClass getDynaClass() { 219 220 return (this.dynaClass); 221 222 } 223 224 225 236 public void remove(String name, String key) { 237 238 throw new UnsupportedOperationException 239 ("FIXME - mapped operations not currently supported"); 240 241 } 242 243 244 257 public void set(String name, Object value) { 258 259 if (dynaClass.getDynaProperty(name) == null) { 260 throw new IllegalArgumentException (name); 261 } 262 try { 263 dynaClass.getResultSet().updateObject(name, value); 264 } catch (SQLException e) { 265 throw new RuntimeException 266 ("set(" + name + "): SQLException: " + e); 267 } 268 269 } 270 271 272 288 public void set(String name, int index, Object value) { 289 290 throw new UnsupportedOperationException 291 ("FIXME - indexed properties not currently supported"); 292 293 } 294 295 296 310 public void set(String name, String key, Object value) { 311 312 throw new UnsupportedOperationException 313 ("FIXME - mapped properties not currently supported"); 314 315 } 316 317 318 320 321 324 public boolean hasNext() { 325 326 try { 327 advance(); 328 return (!eof); 329 } catch (SQLException e) { 330 throw new RuntimeException ("hasNext(): SQLException: " + e); 331 } 332 333 } 334 335 336 339 public Object next() { 340 341 try { 342 advance(); 343 if (eof) { 344 throw new NoSuchElementException (); 345 } 346 current = false; 347 return (this); 348 } catch (SQLException e) { 349 throw new RuntimeException ("next(): SQLException: " + e); 350 } 351 352 } 353 354 355 359 public void remove() { 360 361 throw new UnsupportedOperationException ("remove()"); 362 363 } 364 365 366 368 369 375 protected void advance() throws SQLException { 376 377 if (!current && !eof) { 378 if (dynaClass.getResultSet().next()) { 379 current = true; 380 eof = false; 381 } else { 382 current = false; 383 eof = true; 384 } 385 } 386 387 } 388 389 390 } 391 | Popular Tags |