File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\index\LinkedCursor.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.PreparedStatement;
10 import java.sql.ResultSet;
11 import java.sql.SQLException;
12
13 import org.h2.engine.Session;
14 import org.h2.message.DbException;
15 import org.h2.result.Row;
16 import org.h2.result.SearchRow;
17 import org.h2.table.Column;
18 import org.h2.table.TableLink;
19 import org.h2.value.DataType;
20 import org.h2.value.Value;
21
22 /**
23 * The cursor implementation for the linked index.
24 */
25 public class LinkedCursor implements Cursor {
26
27 private final TableLink tableLink;
28 private final PreparedStatement prep;
29 private final String sql;
30 private final Session session;
31 private final ResultSet rs;
32 private Row current;
33
34 LinkedCursor(TableLink tableLink, ResultSet rs, Session session, String sql, PreparedStatement prep) {
35 this.session = session;
36 this.tableLink = tableLink;
37 this.rs = rs;
38 this.sql = sql;
39 this.prep = prep;
40 }
41
42 public Row get() {
43 return current;
44 }
45
46 public SearchRow getSearchRow() {
47 return current;
48 }
49
50 public boolean next() {
51 try {
52 boolean result = rs.next();
53 if (!result) {
54 rs.close();
55 tableLink.reusePreparedStatement(prep, sql);
56 current = null;
57 return false;
58 }
59 } catch (SQLException e) {
60 throw DbException.convert(e);
61 }
62 current = tableLink.getTemplateRow();
63 for (int i = 0; i < current.getColumnCount(); i++) {
64 Column col = tableLink.getColumn(i);
65 Value v = DataType.readValue(session, rs, i + 1, col.getType());
66 current.setValue(i, v);
67 }
68 return true;
69 }
70
71 public boolean previous() {
72 throw DbException.throwInternalError();
73 }
74
75 }
76