01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (http://h2database.com/html/license.html).
04: * Initial Developer: H2 Group
05: */
06: package org.h2.index;
07:
08: import java.sql.SQLException;
09:
10: import org.h2.store.DataPage;
11: import org.h2.store.Record;
12:
13: /**
14: * The head page of a b-tree index. There is exactly one head page for each such
15: * index, and it contains meta data such as the location of the root page.
16: * Unlike the root page of a b-tree index, the head page always stays at the
17: * same place.
18: */
19: public class BtreeHead extends Record {
20:
21: private int rootPosition;
22: private boolean consistent;
23:
24: public BtreeHead() {
25: // nothing to do
26: }
27:
28: public BtreeHead(DataPage s) throws SQLException {
29: rootPosition = s.readInt();
30: consistent = s.readInt() == 1;
31: }
32:
33: public boolean getConsistent() {
34: return consistent;
35: }
36:
37: public void setConsistent(boolean b) {
38: this .consistent = b;
39: }
40:
41: public int getByteCount(DataPage dummy) throws SQLException {
42: return 1 + dummy.getIntLen();
43: }
44:
45: public void write(DataPage buff) throws SQLException {
46: buff.writeByte((byte) 'H');
47: buff.writeInt(rootPosition);
48: buff.writeInt(consistent ? 1 : 0);
49: }
50:
51: void setRootPosition(int rootPosition) {
52: this .rootPosition = rootPosition;
53: }
54:
55: int getRootPosition() {
56: return rootPosition;
57: }
58:
59: public boolean isPinned() {
60: return true;
61: }
62:
63: }
|