File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\index\ViewCursor.java.html

1 /*
2 * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
3 * Version 1.0, and under the Eclipse Public License, Version 1.0
4 * (http://h2database.com/html/license.html).
5 * Initial Developer: H2 Group
6 */
7 package org.h2.index;
8
9 import org.h2.message.DbException;
10 import org.h2.result.ResultInterface;
11 import org.h2.result.Row;
12 import org.h2.result.SearchRow;
13 import org.h2.table.Table;
14 import org.h2.value.Value;
15 import org.h2.value.ValueNull;
16
17 /**
18 * The cursor implementation of a view index.
19 */
20 public class ViewCursor implements Cursor {
21
22 private final Table table;
23 private final Index index;
24 private final ResultInterface result;
25 private final SearchRow first, last;
26 private Row current;
27
28 ViewCursor(Index index, ResultInterface result, SearchRow first, SearchRow last) {
29 this.table = index.getTable();
30 this.index = index;
31 this.result = result;
32 this.first = first;
33 this.last = last;
34 }
35
36 public Row get() {
37 return current;
38 }
39
40 public SearchRow getSearchRow() {
41 return current;
42 }
43
44 public boolean next() {
45 while (true) {
46 boolean res = result.next();
47 if (!res) {
48 result.close();
49 current = null;
50 return false;
51 }
52 current = table.getTemplateRow();
53 Value[] values = result.currentRow();
54 for (int i = 0, len = current.getColumnCount(); i < len; i++) {
55 Value v = i < values.length ? values[i] : ValueNull.INSTANCE;
56 current.setValue(i, v);
57 }
58 int comp;
59 if (first != null) {
60 comp = index.compareRows(current, first);
61 if (comp < 0) {
62 continue;
63 }
64 }
65 if (last != null) {
66 comp = index.compareRows(current, last);
67 if (comp > 0) {
68 continue;
69 }
70 }
71 return true;
72 }
73 }
74
75 public boolean previous() {
76 throw DbException.throwInternalError();
77 }
78
79 }
80