1 5 package org.h2.index; 6 7 import java.sql.SQLException ; 8 9 import org.h2.engine.Session; 10 import org.h2.result.Row; 11 import org.h2.result.SearchRow; 12 import org.h2.store.DataPage; 13 import org.h2.store.DiskFile; 14 import org.h2.store.Record; 15 import org.h2.table.Column; 16 import org.h2.util.ObjectArray; 17 import org.h2.value.Value; 18 19 22 public abstract class BtreePage extends Record { 23 26 protected static final int BLOCKS_PER_PAGE = 1024 / DiskFile.BLOCK_SIZE; 27 28 protected BtreeIndex index; 29 protected ObjectArray pageData; 30 protected boolean root; 31 32 BtreePage(BtreeIndex index) { 33 this.index = index; 34 } 35 36 abstract int add(Row row, Session session) throws SQLException ; 37 38 abstract SearchRow remove(Session session, Row row, int level) throws SQLException ; 40 abstract BtreePage split(Session session, int splitPoint) throws SQLException ; 41 abstract boolean findFirst(BtreeCursor cursor, SearchRow row) throws SQLException ; 42 abstract SearchRow getFirst() throws SQLException ; 43 abstract SearchRow getLast() throws SQLException ; 44 abstract void next(BtreeCursor cursor, int i) throws SQLException ; 45 abstract void first(BtreeCursor cursor) throws SQLException ; 46 abstract int getRealByteCount() throws SQLException ; 47 48 SearchRow getData(int i) throws SQLException { 49 return (SearchRow) pageData.get(i); 50 } 51 52 public int getByteCount(DataPage dummy) throws SQLException { 53 return DiskFile.BLOCK_SIZE*BLOCKS_PER_PAGE; 54 } 55 56 int getSplitPoint() throws SQLException { 57 if(pageData.size() == 1) { 58 return 0; 59 } 60 int size = getRealByteCount(); 61 if(size >= DiskFile.BLOCK_SIZE*BLOCKS_PER_PAGE) { 62 return pageData.size() / 2; 63 } 64 return 0; 65 } 66 67 public boolean isEmpty() { 68 return false; 69 } 70 71 int getRowSize(DataPage dummy, SearchRow row) throws SQLException { 72 int rowsize = dummy.getIntLen(); 73 Column[] columns = index.getColumns(); 74 for (int j = 0; j < columns.length; j++) { 75 Value v = row.getValue(columns[j].getColumnId()); 76 rowsize += dummy.getValueLen(v); 77 } 78 return rowsize; 79 } 80 81 void setRoot(boolean root) { 82 this.root = root; 83 } 84 85 public boolean isPinned() { 86 return root; 87 } 88 89 public abstract String print(String indent) throws SQLException ; 90 } 91 | Popular Tags |