KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > index > LinkedCursor


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.index;
6
7 import java.sql.ResultSet JavaDoc;
8 import java.sql.SQLException JavaDoc;
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 /**
19  * @author Thomas
20  */

21
22 public class LinkedCursor implements Cursor {
23
24     private Session session;
25     private Row current;
26     private ResultSet JavaDoc rs;
27     private Table table;
28
29     LinkedCursor(Table table, ResultSet JavaDoc 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 JavaDoc {
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