001 package railo.runtime.type.it; 002 003 import java.util.Iterator; 004 005 import railo.runtime.exp.PageException; 006 import railo.runtime.exp.PageRuntimeException; 007 import railo.runtime.type.Collection.Key; 008 import railo.runtime.type.Query; 009 import railo.runtime.type.Struct; 010 import railo.runtime.type.StructImpl; 011 012 public class ForEachQueryIterator implements Iterator { 013 014 private Query qry; 015 private int pid; 016 private int start,current=0; 017 018 019 public ForEachQueryIterator(Query qry, int pid){ 020 this.qry=qry; 021 this.pid=pid; 022 this.start=qry.getCurrentrow(pid); 023 } 024 025 @Override 026 public boolean hasNext() { 027 return current<qry.getRecordcount(); 028 } 029 030 @Override 031 public Object next() { 032 try { 033 if(qry.go(++current,pid)) { 034 Struct sct=new StructImpl(); 035 Key[] names = qry.getColumnNames(); 036 for(int i=0;i<names.length;i++){ 037 sct.setEL(names[i], qry.get(names[i],null)); 038 } 039 return sct; 040 } 041 } catch (PageException pe) { 042 throw new PageRuntimeException(pe); 043 } 044 return null; 045 } 046 047 @Override 048 public void remove() { 049 try { 050 qry.removeRow(current); 051 } catch (PageException pe) { 052 throw new PageRuntimeException(pe); 053 } 054 } 055 056 public void reset() throws PageException { 057 qry.go(start,pid); 058 } 059 060 }