01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (http://h2database.com/html/license.html).
04: * Initial Developer: H2 Group
05: */
06: package org.h2.index;
07:
08: import java.sql.ResultSet;
09: import java.sql.SQLException;
10:
11: import org.h2.engine.Session;
12: import org.h2.message.Message;
13: import org.h2.result.Row;
14: import org.h2.result.SearchRow;
15: import org.h2.table.Column;
16: import org.h2.table.Table;
17: import org.h2.value.DataType;
18: import org.h2.value.Value;
19:
20: /**
21: * The cursor implementation for the linked index.
22: */
23: public class LinkedCursor implements Cursor {
24:
25: private Session session;
26: private Row current;
27: private ResultSet rs;
28: private Table table;
29:
30: LinkedCursor(Table table, ResultSet rs, Session session) {
31: this .session = session;
32: this .table = table;
33: this .rs = rs;
34: }
35:
36: public Row get() {
37: return current;
38: }
39:
40: public SearchRow getSearchRow() throws SQLException {
41: return current;
42: }
43:
44: public int getPos() {
45: throw Message.getInternalError();
46: }
47:
48: public boolean next() throws SQLException {
49: boolean result = rs.next();
50: if (!result) {
51: rs.close();
52: current = null;
53: return false;
54: }
55: current = table.getTemplateRow();
56: for (int i = 0; i < current.getColumnCount(); i++) {
57: Column col = table.getColumn(i);
58: Value v = DataType.readValue(session, rs, i + 1, col
59: .getType());
60: current.setValue(i, v);
61: }
62: return true;
63: }
64:
65: }
|