com.sleepycat.je.dbi
Class DatabaseImpl

java.lang.Object
  extended by com.sleepycat.je.dbi.DatabaseImpl
All Implemented Interfaces:
LogReadable, LogWritable, Cloneable

public class DatabaseImpl
extends Object
implements LogWritable, LogReadable, Cloneable

The underlying object for a given database.


Nested Class Summary
(package private) static class DatabaseImpl.StatsAccumulator
           
 
Constructor Summary
DatabaseImpl()
          Create an empty database object for initialization from the log.
DatabaseImpl(String dbName, DatabaseId id, EnvironmentImpl envImpl, DatabaseConfig dbConfig)
          Create a database object for a new database.
 
Method Summary
 void addReferringHandle(Database db)
          Add a referring handle
 void checkIsDeleted(String operation)
           
 Object clone()
          Clone.
 void deleteAndReleaseINs()
          Purge a DatabaseImpl and corresponding MapLN in the db mapping tree.
 void dumpLog(StringBuffer sb, boolean verbose)
          Write the object into the string buffer for log dumping.
 String dumpString(int nSpaces)
           
 Database findPrimaryDatabase()
          For this secondary database return the primary that it is associated with, or null if not associated with any primary.
 int getBinDeltaPercent()
           
 int getBinMaxDeltas()
           
 Comparator getBtreeComparator()
           
 EnvironmentImpl getDbEnvironment()
           
 String getDebugName()
           
 Comparator getDuplicateComparator()
           
 DatabaseStats getEmptyStats()
           
 long getEofNodeId()
           
 DatabaseId getId()
           
 boolean getIsDeleted()
           
 int getLogSize()
           
 String getName()
           
 int getNodeMaxDupTreeEntries()
           
 int getNodeMaxEntries()
           
(package private)  int getReferringHandleCount()
           
 boolean getSortedDuplicates()
           
 long getTransactionId()
           
 Tree getTree()
           
 boolean hasOpenHandles()
          Returns whether one or more handles are open.
static Comparator instantiateComparator(Class comparator, String comparatorType)
          Used both to read from the log and to validate a comparator when set in DatabaseConfig.
 boolean isTransactional()
           
 boolean logEntryIsTransactional()
           
 void preload(long maxBytes, long maxMillisecs)
          Preload the cache, using up to maxBytes bytes or maxMillsecs msec.
 void readFromLog(ByteBuffer itemBuffer, byte entryTypeVersion)
          Initialize this object from the data in itemBuf.
 int recordObsoleteNodes()
          Called when this database is truncated or removed to record the number of obsolete nodes that should be counted for the deleted tree.
 void removeReferringHandle(Database db)
          Decrement the reference count.
static String serializeComparator(Comparator comparator)
          Used both to write to the log and to validate a comparator when set in DatabaseConfig.
 void setBtreeComparator(Comparator btreeComparator)
          Set the btree comparison function for this database.
 void setDebugDatabaseName(String debugName)
           
 void setDuplicateComparator(Comparator duplicateComparator)
          Set the duplicate comparison function for this database.
 void setEnvironmentImpl(EnvironmentImpl envImpl)
          Set the db environment during recovery, after instantiating the database from the log
(package private)  void setId(DatabaseId id)
           
 void setTransactional(boolean transactional)
          Sets the transactional property for the first opened handle.
(package private)  void setTree(Tree tree)
           
 DatabaseStats stat(StatsConfig config)
           
 boolean verify(VerifyConfig config, DatabaseStats emptyStats)
           
 void writeToLog(ByteBuffer logBuffer)
          Serialize this object into the buffer.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatabaseImpl

public DatabaseImpl(String dbName,
                    DatabaseId id,
                    EnvironmentImpl envImpl,
                    DatabaseConfig dbConfig)
             throws DatabaseException
Create a database object for a new database.

Throws:
DatabaseException

DatabaseImpl

public DatabaseImpl()
             throws DatabaseException
Create an empty database object for initialization from the log. Note that the rest of the initialization comes from readFromLog(), except for the debugDatabaseName, which is set by the caller.

Throws:
DatabaseException
Method Detail

setDebugDatabaseName

public void setDebugDatabaseName(String debugName)

getDebugName

public String getDebugName()

clone

public Object clone()
             throws CloneNotSupportedException
Clone. For now just pass off to the super class for a field-by-field copy.

Overrides:
clone in class Object
Throws:
CloneNotSupportedException

getTree

public Tree getTree()
Returns:
the database tree.

setTree

void setTree(Tree tree)

getId

public DatabaseId getId()
Returns:
the database id.

setId

void setId(DatabaseId id)

getEofNodeId

public long getEofNodeId()

isTransactional

public boolean isTransactional()
Returns:
true if this database is transactional.

setTransactional

public void setTransactional(boolean transactional)
Sets the transactional property for the first opened handle.


getSortedDuplicates

public boolean getSortedDuplicates()
Returns:
true if duplicates are allowed in this database.

getNodeMaxEntries

public int getNodeMaxEntries()

getNodeMaxDupTreeEntries

public int getNodeMaxDupTreeEntries()

setDuplicateComparator

public void setDuplicateComparator(Comparator duplicateComparator)
Set the duplicate comparison function for this database.

Parameters:
duplicateComparator - - The Duplicate Comparison function.

setBtreeComparator

public void setBtreeComparator(Comparator btreeComparator)
Set the btree comparison function for this database.

Parameters:
btreeComparator - - The btree Comparison function.

getBtreeComparator

public Comparator getBtreeComparator()
Returns:
the btree Comparator object.

getDuplicateComparator

public Comparator getDuplicateComparator()
Returns:
the duplicate Comparator object.

setEnvironmentImpl

public void setEnvironmentImpl(EnvironmentImpl envImpl)
                        throws DatabaseException
Set the db environment during recovery, after instantiating the database from the log

Throws:
DatabaseException

getDbEnvironment

public EnvironmentImpl getDbEnvironment()
Returns:
the database environment.

hasOpenHandles

public boolean hasOpenHandles()
Returns whether one or more handles are open.


addReferringHandle

public void addReferringHandle(Database db)
Add a referring handle


removeReferringHandle

public void removeReferringHandle(Database db)
Decrement the reference count.


getReferringHandleCount

int getReferringHandleCount()
Returns:
the referring handle count.

findPrimaryDatabase

public Database findPrimaryDatabase()
                             throws DatabaseException
For this secondary database return the primary that it is associated with, or null if not associated with any primary. Note that not all handles need be associated with a primary.

Throws:
DatabaseException

getName

public String getName()
               throws DatabaseException
Throws:
DatabaseException

getIsDeleted

public boolean getIsDeleted()

deleteAndReleaseINs

public void deleteAndReleaseINs()
                         throws DatabaseException
Purge a DatabaseImpl and corresponding MapLN in the db mapping tree. Purging consists of removing all related INs from the db mapping tree and deleting the related MapLN. Used at the a transaction end in these cases: - purge the deleted database after a commit of Environment.removeDatabase - purge the deleted database after a commit of Environment.truncateDatabase - purge the newly created database after an abort of Environment.truncateDatabase

Throws:
DatabaseException

checkIsDeleted

public void checkIsDeleted(String operation)
                    throws DatabaseException
Throws:
DatabaseException

recordObsoleteNodes

public int recordObsoleteNodes()
                        throws DatabaseException
Called when this database is truncated or removed to record the number of obsolete nodes that should be counted for the deleted tree. We save the number of obsolete nodes here, but the counting in the utilization profile does not actually occur until deleteAndReleaseINs() is called when the transaction is committed.

Throws:
DatabaseException

stat

public DatabaseStats stat(StatsConfig config)
                   throws DatabaseException
Throws:
DatabaseException

verify

public boolean verify(VerifyConfig config,
                      DatabaseStats emptyStats)
               throws DatabaseException
Throws:
DatabaseException

getEmptyStats

public DatabaseStats getEmptyStats()

preload

public void preload(long maxBytes,
                    long maxMillisecs)
             throws DatabaseException
Preload the cache, using up to maxBytes bytes or maxMillsecs msec.

Throws:
DatabaseException

dumpString

public String dumpString(int nSpaces)

getLogSize

public int getLogSize()
Specified by:
getLogSize in interface LogWritable
Returns:
number of bytes used to store this object.
See Also:
LogWritable.getLogSize()

writeToLog

public void writeToLog(ByteBuffer logBuffer)
Description copied from interface: LogWritable
Serialize this object into the buffer.

Specified by:
writeToLog in interface LogWritable
Parameters:
logBuffer - is the destination buffer
See Also:
LogWritable.writeToLog(java.nio.ByteBuffer)

readFromLog

public void readFromLog(ByteBuffer itemBuffer,
                        byte entryTypeVersion)
                 throws LogException
Description copied from interface: LogReadable
Initialize this object from the data in itemBuf.

Specified by:
readFromLog in interface LogReadable
Throws:
LogException
See Also:
LogReadable.readFromLog(java.nio.ByteBuffer, byte)

dumpLog

public void dumpLog(StringBuffer sb,
                    boolean verbose)
Description copied from interface: LogReadable
Write the object into the string buffer for log dumping. Each object should be dumped without indentation or new lines and should be valid XML.

Specified by:
dumpLog in interface LogReadable
Parameters:
sb - destination string buffer
verbose - if true, dump the full, verbose version
See Also:
LogReadable.dumpLog(java.lang.StringBuffer, boolean)

logEntryIsTransactional

public boolean logEntryIsTransactional()
Specified by:
logEntryIsTransactional in interface LogReadable
Returns:
true if the LogEntry is a transactional log entry type.
See Also:
LogReadable.logEntryIsTransactional()

getTransactionId

public long getTransactionId()
Specified by:
getTransactionId in interface LogReadable
Returns:
return the transaction id if this log entry is transactional, 0 otherwise.
See Also:
LogReadable.getTransactionId()

serializeComparator

public static String serializeComparator(Comparator comparator)
Used both to write to the log and to validate a comparator when set in DatabaseConfig.


instantiateComparator

public static Comparator instantiateComparator(Class comparator,
                                               String comparatorType)
                                        throws LogException
Used both to read from the log and to validate a comparator when set in DatabaseConfig.

Throws:
LogException

getBinDeltaPercent

public int getBinDeltaPercent()

getBinMaxDeltas

public int getBinMaxDeltas()


Copyright 2004-2005 Sleepycat, Inc. All Rights Reserved.