KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > index > BtreeCursor


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.index;
6
7 import java.sql.SQLException JavaDoc;
8
9 import org.h2.engine.Constants;
10 import org.h2.message.Message;
11 import org.h2.result.Row;
12 import org.h2.result.SearchRow;
13
14 /**
15  * @author Thomas
16  */

17 public class BtreeCursor implements Cursor {
18     private BtreeIndex index;
19     private BtreePosition top;
20     private Row current;
21     private boolean first;
22     private SearchRow last;
23
24     BtreeCursor(BtreeIndex index, SearchRow last) {
25         this.index = index;
26         this.last = last;
27         first = true;
28     }
29
30     void setStackPosition(int position) {
31         top.position = position;
32     }
33
34     void push(BtreePage page, int position) {
35         if (Constants.CHECK && (top != null && top.page == page)) {
36             throw Message.getInternalError();
37         }
38         top = new BtreePosition(page, position, top);
39     }
40
41     BtreePosition pop() {
42         BtreePosition t = top;
43         if (t == null) {
44             return null;
45         }
46         top = top.next;
47         return t;
48     }
49
50     void setCurrentRow(int pos) throws SQLException JavaDoc {
51         current = pos == POS_NO_ROW ? null : index.getRow(pos);
52     }
53     
54     public Row get() throws SQLException JavaDoc {
55         return current;
56     }
57
58     public int getPos() {
59         return current.getPos();
60     }
61
62     public boolean next() throws SQLException JavaDoc {
63         if (first) {
64             first = false;
65             return current != null;
66         }
67         top.page.next(this, top.position);
68         if(current != null && last != null) {
69             if (index.compareRows(current, last) > 0) {
70                 current = null;
71             }
72         }
73         return current != null;
74     }
75
76 }
77
Popular Tags