org.netbeans.mdr.persistence.btreeimpl.btreestorage
Class BtreeFileSource

java.lang.Object
  extended byorg.netbeans.mdr.persistence.btreeimpl.btreestorage.BtreeFileSource
All Implemented Interfaces:
BtreePageSource, FileCache.NotifyOnCommit, MofidGenerator

public class BtreeFileSource
extends java.lang.Object
implements BtreePageSource, FileCache.NotifyOnCommit

BtreePageSource implementation for pages which are stored directly in a file (the primary index pages) rather than as repository objects. The file access is all handled by the FileCache class.

Version:
1.0
Author:
Dana Bergen

Constructor Summary
BtreeFileSource(int fileId, FileCache fileCache, int pageSize, boolean isNew, MofidGenerator mGen, BtreeStorage storage)
          Constructor for a BtreeFileSource from a new or existing index file.
 
Method Summary
 void dirtyPage(BtreePage page)
          Notifies the btree that the caller is going to modify this page.
 java.lang.String getMofidPrefix()
          Get the prefix for this repository
 long getNextMofid()
          get the next unique ID for this repository
 BtreePage getPage(byte[] pageId, Btree btree)
          Get a BtreePage by its pageId.
 EntryTypeInfo getPageIdInfo()
          Get an EntryTypeInfo for the datatype of this BtreePageSource's page IDs.
 int getPageIdLength()
          Returns the length of a page ID.
 int getPageSize()
          Returns the size of a page.
 BtreePage getRootPage(Btree btree)
          Return the root page if it already exists, otherwise create it.
 BtreeStorage getStorage()
           
 boolean isNoPage(byte[] pageId)
          Test whether the passed-in pageId contains the special value noPageId
 BigKeyPage newBigKeyPage(Btree btree)
          Returns a newly allocated BigKeyPage.
 BtreePage newPage(Btree btree)
          Returns a newly allocated btree page.
 void prepareToCommit()
          Prepares all cached modified pages to be written out.
 void setNoPage(byte[] pageId)
          Set the passed-in pageId to contain the special value noPageId
 void unpinPage(BigKeyPage page)
          Notify the BtreePageSource that the caller is done using this page.
 void unpinPage(BtreePage page)
          Notifies the btree that the caller is done using this page.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BtreeFileSource

public BtreeFileSource(int fileId,
                       FileCache fileCache,
                       int pageSize,
                       boolean isNew,
                       MofidGenerator mGen,
                       BtreeStorage storage)
                throws StorageException
Constructor for a BtreeFileSource from a new or existing index file.

Parameters:
fileId - file ID to use in FileCache requests
fileCache - source of index pages
pageSize - size of index pages
isNew - true if this index is being newly created
mGen - Mofid generator
Method Detail

getPageIdInfo

public EntryTypeInfo getPageIdInfo()
Description copied from interface: BtreePageSource
Get an EntryTypeInfo for the datatype of this BtreePageSource's page IDs.

Specified by:
getPageIdInfo in interface BtreePageSource

setNoPage

public void setNoPage(byte[] pageId)
Set the passed-in pageId to contain the special value noPageId

Specified by:
setNoPage in interface BtreePageSource
Parameters:
pageId - byte array to be filled in

isNoPage

public boolean isNoPage(byte[] pageId)
Test whether the passed-in pageId contains the special value noPageId

Specified by:
isNoPage in interface BtreePageSource
Returns:
true if the pageId is the null page ID, otherwise false

prepareToCommit

public void prepareToCommit()
                     throws StorageException
Prepares all cached modified pages to be written out.

Specified by:
prepareToCommit in interface FileCache.NotifyOnCommit
Throws:
StorageException

getRootPage

public BtreePage getRootPage(Btree btree)
                      throws StorageException
Return the root page if it already exists, otherwise create it.

Specified by:
getRootPage in interface BtreePageSource
Parameters:
btree - Btree
Returns:
BtreePage which is the root page
Throws:
StorageException

getPage

public BtreePage getPage(byte[] pageId,
                         Btree btree)
                  throws StorageException
Get a BtreePage by its pageId.

Specified by:
getPage in interface BtreePageSource
Parameters:
pageId - Byte array containing pageId
btree - btree to which the page belongs
Returns:
The page identified by pageId.
Throws:
StorageException - If the page is not valid

newPage

public BtreePage newPage(Btree btree)
                  throws StorageException
Returns a newly allocated btree page.

Specified by:
newPage in interface BtreePageSource
Parameters:
btree - btree to which the page belongs
Returns:
A new BtreePage
Throws:
StorageException - If the page is not valid

newBigKeyPage

public BigKeyPage newBigKeyPage(Btree btree)
                         throws StorageException
Returns a newly allocated BigKeyPage. BigKeyPages are not recycled. They are only cached while in use.

Specified by:
newBigKeyPage in interface BtreePageSource
Parameters:
btree - btree to which the page belongs
Returns:
the BigKeyPage
Throws:
StorageException

unpinPage

public void unpinPage(BtreePage page)
Notifies the btree that the caller is done using this page. This decrements its pinned count in the btree cache. It does not change its pinned status in the FileCache; that only happens when a page is removed from the btree cache.

Specified by:
unpinPage in interface BtreePageSource
Parameters:
page - BtreePage to be unpinned

unpinPage

public void unpinPage(BigKeyPage page)
               throws StorageException
Description copied from interface: BtreePageSource
Notify the BtreePageSource that the caller is done using this page.

Specified by:
unpinPage in interface BtreePageSource
Parameters:
page - BigKeyPage
Throws:
StorageException

dirtyPage

public void dirtyPage(BtreePage page)
               throws StorageException
Notifies the btree that the caller is going to modify this page. This must be called prior to modifying the page contents.

Specified by:
dirtyPage in interface BtreePageSource
Parameters:
page - The page being modified
Throws:
StorageException

getPageIdLength

public int getPageIdLength()
Description copied from interface: BtreePageSource
Returns the length of a page ID.

Specified by:
getPageIdLength in interface BtreePageSource
Returns:
length of a page ID from this BtreePageSource

getPageSize

public int getPageSize()
Description copied from interface: BtreePageSource
Returns the size of a page.

Specified by:
getPageSize in interface BtreePageSource
Returns:
size of a page from this BtreePageSource

getNextMofid

public long getNextMofid()
Description copied from interface: MofidGenerator
get the next unique ID for this repository

Specified by:
getNextMofid in interface MofidGenerator

getMofidPrefix

public java.lang.String getMofidPrefix()
Description copied from interface: MofidGenerator
Get the prefix for this repository

Specified by:
getMofidPrefix in interface MofidGenerator

getStorage

public BtreeStorage getStorage()
Specified by:
getStorage in interface BtreePageSource


Copyright © 2005 Apache Software Foundation. All Rights Reserved.