1 23 24 package org.objectweb.jorm.mapper.rdb.genclass; 25 26 import org.objectweb.jorm.genclass.api.FieldDesc; 27 import org.objectweb.jorm.mapper.rdb.adapter.api.RdbAdapter; 28 import org.objectweb.jorm.api.PNameIterator; 29 import org.objectweb.jorm.api.PException; 30 import org.objectweb.jorm.api.PExceptionIO; 31 32 import java.sql.ResultSet ; 33 import java.sql.SQLException ; 34 import java.sql.PreparedStatement ; 35 import java.util.NoSuchElementException ; 36 37 41 public class RdbGenClassPNGIterator 42 extends RdbGenClassNameGetter 43 implements PNameIterator { 44 45 private boolean hasNext; 46 private boolean isForw; 47 private RdbGenClassMapping gcm; 48 51 private boolean prefetching; 52 53 public RdbGenClassPNGIterator(PreparedStatement ps, 54 ResultSet rs, 55 FieldDesc[] rfds, 56 RdbGenClassMapping gcm, 57 boolean prefetching, 58 RdbAdapter adapter) throws SQLException { 59 super(ps, rs, rfds, 0, adapter); 60 this.prefetching = prefetching; 61 this.gcm = gcm; 62 hasNext = resultSet.next(); 63 isForw = true; 64 } 65 66 public boolean hasNext() { 67 if (!isForw) { 68 try { 69 hasNext = resultSet.next(); 70 } catch (SQLException e) { 71 e.printStackTrace(); 72 hasNext = false; 73 } 74 isForw = true; 75 } 76 return hasNext; 77 } 78 79 public Object next() throws NoSuchElementException { 80 try { 81 if (!isForw) { 82 hasNext = resultSet.next(); 83 isForw = true; 84 } 85 if (!hasNext) { 86 throw new NoSuchElementException (); 87 } 88 isForw = false; 89 return (elemFields.length == 1 90 ? gcm.decodeSingle(elemFields[0], resultSet, 1) 91 : gcm.getPBinder().decodeAbstract(this, null)); 92 } catch (Exception e) { 93 throw new NoSuchElementException ( 94 "Impossible to decode to a PName: " + e.getMessage()); 95 } 96 } 97 98 public void remove() throws UnsupportedOperationException { 99 throw new UnsupportedOperationException (); 100 } 101 102 public void close() throws PException { 103 if (!prefetching) { 104 hasNext = false; 105 isForw = true; 106 try { 107 resultSet.close(); 108 } catch (SQLException e) { 109 throw new PExceptionIO(e); 110 } 111 } 112 } 113 } 114 | Popular Tags |