1 | /* |
2 | * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0, |
3 | * and the EPL 1.0 (http://h2database.com/html/license.html). |
4 | * Initial Developer: H2 Group |
5 | */ |
6 | package org.h2.index; |
7 | |
8 | import org.h2.message.DbException; |
9 | import org.h2.result.ResultInterface; |
10 | import org.h2.result.Row; |
11 | import org.h2.result.SearchRow; |
12 | import org.h2.value.Value; |
13 | |
14 | /** |
15 | * A cursor for a function that returns a result. |
16 | */ |
17 | public class FunctionCursor implements Cursor { |
18 | |
19 | private final ResultInterface result; |
20 | private Value[] values; |
21 | private Row row; |
22 | |
23 | FunctionCursor(ResultInterface result) { |
24 | this.result = result; |
25 | } |
26 | |
27 | @Override |
28 | public Row get() { |
29 | if (values == null) { |
30 | return null; |
31 | } |
32 | if (row == null) { |
33 | row = new Row(values, 1); |
34 | } |
35 | return row; |
36 | } |
37 | |
38 | @Override |
39 | public SearchRow getSearchRow() { |
40 | return get(); |
41 | } |
42 | |
43 | @Override |
44 | public boolean next() { |
45 | row = null; |
46 | if (result != null && result.next()) { |
47 | values = result.currentRow(); |
48 | } else { |
49 | values = null; |
50 | } |
51 | return values != null; |
52 | } |
53 | |
54 | @Override |
55 | public boolean previous() { |
56 | throw DbException.throwInternalError(); |
57 | } |
58 | |
59 | } |