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.SQLException;
09:
10: import org.h2.message.Message;
11: import org.h2.result.LocalResult;
12: import org.h2.result.Row;
13: import org.h2.result.SearchRow;
14: import org.h2.table.Table;
15: import org.h2.value.Value;
16: import org.h2.value.ValueNull;
17:
18: /**
19: * The cursor implementation of a view index.
20: */
21: public class ViewCursor implements Cursor {
22:
23: private Table table;
24: private LocalResult result;
25: private Row current;
26:
27: ViewCursor(Table table, LocalResult result) {
28: this .table = table;
29: this .result = result;
30: }
31:
32: public Row get() {
33: return current;
34: }
35:
36: public SearchRow getSearchRow() {
37: return current;
38: }
39:
40: public int getPos() {
41: throw Message.getInternalError();
42: }
43:
44: public boolean next() throws SQLException {
45: boolean res = result.next();
46: if (!res) {
47: result.reset();
48: current = null;
49: return false;
50: }
51: current = table.getTemplateRow();
52: Value[] values = result.currentRow();
53: for (int i = 0; i < current.getColumnCount(); i++) {
54: Value v = i < values.length ? values[i]
55: : ValueNull.INSTANCE;
56: current.setValue(i, v);
57: }
58: return true;
59: }
60:
61: }
|