1 5 package org.h2.index; 6 7 import java.sql.ResultSet ; 8 import java.sql.SQLException ; 9 10 import org.h2.engine.Session; 11 import org.h2.message.Message; 12 import org.h2.result.Row; 13 import org.h2.table.Column; 14 import org.h2.table.Table; 15 import org.h2.value.DataType; 16 import org.h2.value.Value; 17 18 21 22 public class LinkedCursor implements Cursor { 23 24 private Session session; 25 private Row current; 26 private ResultSet rs; 27 private Table table; 28 29 LinkedCursor(Table table, ResultSet rs, Session session) { 30 this.session = session; 31 this.table = table; 32 this.rs = rs; 33 } 34 35 public Row get() { 36 return current; 37 } 38 39 public int getPos() { 40 throw Message.getInternalError(); 41 } 42 43 44 public boolean next() throws SQLException { 45 boolean result = rs.next(); 46 if(!result) { 47 rs.close(); 48 current = null; 49 return false; 50 } 51 current = table.getTemplateRow(); 52 for(int i=0; i<current.getColumnCount(); i++) { 53 Column col = table.getColumn(i); 54 Value v = DataType.readValue(session, rs, i+1, col.getType()); 55 current.setValue(i, v); 56 } 57 return true; 58 } 59 60 } 61 | Popular Tags |