File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\index\FunctionCursorResultSet.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 java.sql.ResultSet;
10 import java.sql.ResultSetMetaData;
11 import java.sql.SQLException;
12 import org.h2.engine.Session;
13 import org.h2.message.DbException;
14 import org.h2.result.Row;
15 import org.h2.result.SearchRow;
16 import org.h2.value.DataType;
17 import org.h2.value.Value;
18
19 /**
20 * A cursor for a function that returns a JDBC result set.
21 */
22 public class FunctionCursorResultSet implements Cursor {
23
24 private final Session session;
25 private final ResultSet result;
26 private final ResultSetMetaData meta;
27 private Value[] values;
28 private Row row;
29
30 FunctionCursorResultSet(Session session, ResultSet result) {
31 this.session = session;
32 this.result = result;
33 try {
34 this.meta = result.getMetaData();
35 } catch (SQLException e) {
36 throw DbException.convert(e);
37 }
38 }
39
40 public Row get() {
41 if (values == null) {
42 return null;
43 }
44 if (row == null) {
45 row = new Row(values, 1);
46 }
47 return row;
48 }
49
50 public SearchRow getSearchRow() {
51 return get();
52 }
53
54 public boolean next() {
55 row = null;
56 try {
57 if (result != null && result.next()) {
58 int columnCount = meta.getColumnCount();
59 values = new Value[columnCount];
60 for (int i = 0; i < columnCount; i++) {
61 int type = DataType.convertSQLTypeToValueType(meta.getColumnType(i + 1));
62 values[i] = DataType.readValue(session, result, i+1, type);
63 }
64 } else {
65 values = null;
66 }
67 } catch (SQLException e) {
68 throw DbException.convert(e);
69 }
70 return values != null;
71 }
72
73 public boolean previous() {
74 throw DbException.throwInternalError();
75 }
76
77 }