Search in sources :

Example 41 with Page

use of org.h2.store.Page in project h2database by h2database.

the class PageStore method readStaticHeader.

private void readStaticHeader() {
    file.seek(FileStore.HEADER_LENGTH);
    Data page = Data.create(database, new byte[PAGE_SIZE_MIN - FileStore.HEADER_LENGTH]);
    file.readFully(page.getBytes(), 0, PAGE_SIZE_MIN - FileStore.HEADER_LENGTH);
    readCount++;
    setPageSize(page.readInt());
    int writeVersion = page.readByte();
    int readVersion = page.readByte();
    if (readVersion > READ_VERSION) {
        throw DbException.get(ErrorCode.FILE_VERSION_ERROR_1, fileName);
    }
    if (writeVersion > WRITE_VERSION) {
        close();
        database.setReadOnly(true);
        accessMode = "r";
        file = database.openFile(fileName, accessMode, true);
    }
}
Also used : CreateTableData(org.h2.command.ddl.CreateTableData)

Example 42 with Page

use of org.h2.store.Page in project h2database by h2database.

the class PageBtreeIndex method getRowSize.

/**
 * Get the size of a row (only the part that is stored in the index).
 *
 * @param dummy a dummy data page to calculate the size
 * @param row the row
 * @param onlyPosition whether only the position of the row is stored
 * @return the number of bytes
 */
int getRowSize(Data dummy, SearchRow row, boolean onlyPosition) {
    int rowsize = Data.getVarLongLen(row.getKey());
    if (!onlyPosition) {
        for (Column col : columns) {
            Value v = row.getValue(col.getColumnId());
            rowsize += dummy.getValueLen(v);
        }
    }
    return rowsize;
}
Also used : Column(org.h2.table.Column) IndexColumn(org.h2.table.IndexColumn) Value(org.h2.value.Value)

Example 43 with Page

use of org.h2.store.Page in project h2database by h2database.

the class PageBtreeIndex method getPage.

/**
 * Read the given page.
 *
 * @param id the page id
 * @return the page
 */
PageBtree getPage(int id) {
    Page p = store.getPage(id);
    if (p == null) {
        PageBtreeLeaf empty = PageBtreeLeaf.create(this, id, PageBtree.ROOT);
        // could have been created before, but never committed
        store.logUndo(empty, null);
        store.update(empty);
        return empty;
    } else if (!(p instanceof PageBtree)) {
        throw DbException.get(ErrorCode.FILE_CORRUPTED_1, "" + p);
    }
    return (PageBtree) p;
}
Also used : Page(org.h2.store.Page)

Example 44 with Page

use of org.h2.store.Page in project h2database by h2database.

the class PageBtreeLeaf method remove.

@Override
SearchRow remove(SearchRow row) {
    int at = find(row, false, false, true);
    SearchRow delete = getRow(at);
    if (index.compareRows(row, delete) != 0 || delete.getKey() != row.getKey()) {
        throw DbException.get(ErrorCode.ROW_NOT_FOUND_WHEN_DELETING_1, index.getSQL() + ": " + row);
    }
    index.getPageStore().logUndo(this, data);
    if (entryCount == 1) {
        // the page is now empty
        return row;
    }
    removeRow(at);
    memoryChange();
    index.getPageStore().update(this);
    if (at == entryCount) {
        // the last row changed
        return getRow(at - 1);
    }
    // the last row didn't change
    return null;
}
Also used : SearchRow(org.h2.result.SearchRow)

Example 45 with Page

use of org.h2.store.Page in project h2database by h2database.

the class PageBtreeNode method addRowTry.

@Override
int addRowTry(SearchRow row) {
    while (true) {
        int x = find(row, false, true, true);
        PageBtree page = index.getPage(childPageIds[x]);
        int splitPoint = page.addRowTry(row);
        if (splitPoint == -1) {
            break;
        }
        SearchRow pivot = page.getRow(splitPoint - 1);
        index.getPageStore().logUndo(this, data);
        int splitPoint2 = addChildTry(pivot);
        if (splitPoint2 != -1) {
            return splitPoint2;
        }
        PageBtree page2 = page.split(splitPoint);
        readAllRows();
        addChild(x, page2.getPos(), pivot);
        index.getPageStore().update(page);
        index.getPageStore().update(page2);
        index.getPageStore().update(this);
    }
    updateRowCount(1);
    written = false;
    changeCount = index.getPageStore().getChangeCount();
    return -1;
}
Also used : SearchRow(org.h2.result.SearchRow)

Aggregations

CreateTableData (org.h2.command.ddl.CreateTableData)8 Page (org.h2.mvstore.Page)7 Data (org.h2.store.Data)7 Column (org.h2.table.Column)5 IndexColumn (org.h2.table.IndexColumn)5 Value (org.h2.value.Value)5 MVStore (org.h2.mvstore.MVStore)4 Row (org.h2.result.Row)4 SearchRow (org.h2.result.SearchRow)4 IOException (java.io.IOException)3 Connection (java.sql.Connection)3 CRC32 (java.util.zip.CRC32)3 PageBtreeIndex (org.h2.index.PageBtreeIndex)3 PageDataIndex (org.h2.index.PageDataIndex)3 PageIndex (org.h2.index.PageIndex)3 DbException (org.h2.message.DbException)3 Page (org.h2.store.Page)3 ValueString (org.h2.value.ValueString)3 PrintWriter (java.io.PrintWriter)2 ResultSet (java.sql.ResultSet)2