Side of Software
Persistence Library 2.0

sos.db
Class FileDatabase

java.lang.Object
  extended by sos.db.AbstractDatabase
      extended by sos.db.AbstractSerializationDatabase
          extended by sos.db.FileDatabase
All Implemented Interfaces:
java.io.Serializable, Database

public class FileDatabase
extends AbstractSerializationDatabase
implements Database

A persistent database that stores objects in a random-access file.

Logging

Instances of this database log database activity. See AbstractSerializationDatabase for more information.

External Serialization

Proxy objects can be serialized to a stream outside of the database. See AbstractSerializationDatabase for more information.

Since:
1.0
See Also:
AbstractSerializationDatabase, TransactionPolicy, InMemoryDatabase

Field Summary
 
Fields inherited from interface sos.db.Database
logger
 
Constructor Summary
FileDatabase(java.lang.String databaseName, java.lang.String fileName)
          Creates a FileDatabase with the specified database name.
FileDatabase(java.lang.String databaseName, java.lang.String fileName, TransactionPolicy policy)
          Creates a FileDatabase with the specified database name and transaction policy.
 
Method Summary
protected  void doClose()
          Performs the action of close.
protected  boolean doCreate(java.lang.Object root)
          Performs the action of create.
protected  boolean doDelete()
          Performs the action of delete.
protected  boolean doExists()
          Performs the action of exists.
protected  byte[] doFetchObject(long id)
          Returns the serialized object associated with id.
protected  boolean doFlush(LongMap<byte[]> newObjects, LongMap<byte[]> modifiedObjects, Progress progress)
          Adds new objects, re-saves modified objects, and removes old objects from this database in a single, atomic step.
protected  long doNextKey(long fromKey)
          Returns the next key greater than or equal to fromKey that corresponds to an object in this database.
protected  void doOpen(boolean readOnly)
          Performs the action of open.
protected  void doRemoveObject(long oldKey)
          Removes the specified object from this database.
 
Methods inherited from class sos.db.AbstractSerializationDatabase
createDefaultTransactionPolicy, doAbortTransaction, doAddObject, doCommitTransaction, doContainsObject, doGetRoot, doStartTransaction, doTransactionDepth, enableReplaceObject, getName, getTransactionPolicy, logDatabaseClosed, logDatabaseCreated, logDatabaseDeleted, logDatabaseOpened, logObjectAdded, logObjectRemoved, logObjectResaved, logTransactionAborted, logTransactionCommitted, logTransactionStarted, readResolve, replaceObject, resolveObject, setAutoCreateTransactions
 
Methods inherited from class sos.db.AbstractDatabase
abortTransaction, addObject, close, commitTransaction, containsObject, create, delete, exists, getRoot, isOpen, open, startTransaction, transactionDepth
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface sos.db.Database
abortTransaction, addObject, close, commitTransaction, containsObject, create, delete, exists, getName, getRoot, getTransactionPolicy, isOpen, open, startTransaction, transactionDepth
 

Constructor Detail

FileDatabase

public FileDatabase(java.lang.String databaseName,
                    java.lang.String fileName)
Creates a FileDatabase with the specified database name.

Parameters:
databaseName - name of the database
fileName - name of the file to use the database
Throws:
java.lang.NullPointerException - if fileName is null
See Also:
FileDatabase(String,String,TransactionPolicy)

FileDatabase

public FileDatabase(java.lang.String databaseName,
                    java.lang.String fileName,
                    TransactionPolicy policy)
Creates a FileDatabase with the specified database name and transaction policy.

Parameters:
databaseName - name of the database
fileName - name of the file to use the database
policy - policy to use to control transactions (may be null)
Throws:
java.lang.NullPointerException - if fileName is null
Method Detail

doClose

protected void doClose()
                throws java.io.IOException
Description copied from class: AbstractDatabase
Performs the action of close. This method is called inside close if this database is in an acceptable state. It has the same semantics as close.

Overrides:
doClose in class AbstractSerializationDatabase
Throws:
java.io.IOException - if an I/O error occurs
See Also:
AbstractDatabase.close()

doCreate

protected boolean doCreate(java.lang.Object root)
                    throws java.io.IOException
Description copied from class: AbstractDatabase
Performs the action of create. This method is called inside create if this database is in an acceptable state. It has the same semantics as create.

Overrides:
doCreate in class AbstractSerializationDatabase
Parameters:
root - the root of this database
Returns:
true if this database does not exist and was successfully created; false if this database already exists
Throws:
java.io.IOException - if an I/O error occurs
See Also:
AbstractDatabase.create(java.lang.Object)

doDelete

protected boolean doDelete()
                    throws java.io.IOException
Description copied from class: AbstractDatabase
Performs the action of delete. This method is called inside delete if this database is in an acceptable state. It has the same semantics as delete.

Overrides:
doDelete in class AbstractSerializationDatabase
Returns:
true if this database is successfully deleted
Throws:
java.io.IOException - if an I/O error occurs
See Also:
AbstractDatabase.delete()

doExists

protected boolean doExists()
Description copied from class: AbstractDatabase
Performs the action of exists. This method is called inside exists if this database is in an acceptable state. It has the same semantics as exists.

Specified by:
doExists in class AbstractDatabase
Returns:
true if this database exists
See Also:
AbstractDatabase.exists()

doFetchObject

protected byte[] doFetchObject(long id)
                        throws java.io.IOException
Description copied from class: AbstractSerializationDatabase
Returns the serialized object associated with id.

This method is called while holding this database's monitor.

Specified by:
doFetchObject in class AbstractSerializationDatabase
Parameters:
id - id of object to fetch
Returns:
the serialized object associated with id
Throws:
java.io.IOException - if an I/O error occurs

doFlush

protected boolean doFlush(LongMap<byte[]> newObjects,
                          LongMap<byte[]> modifiedObjects,
                          Progress progress)
                   throws java.io.IOException
Description copied from class: AbstractSerializationDatabase
Adds new objects, re-saves modified objects, and removes old objects from this database in a single, atomic step. If any of these steps should fail, the database should roll back to its state prior to the call.

This method is called when a top-level transaction commits. It is called while holding this database's monitor.

Specified by:
doFlush in class AbstractSerializationDatabase
Parameters:
newObjects - a mapping of new ids (as Longs) to new database objects (as byte[]s)
modifiedObjects - a mapping of ids (as Longs) to modified database objects (as byte[]s)
progress - an object to be updated and checked as the flush is occurring (may be null)
Returns:
false if it is interrupted because the progress is canceled; true otherwise
Throws:
java.io.IOException - if an I/O error occurs

doNextKey

protected long doNextKey(long fromKey)
                  throws java.io.IOException
Description copied from class: AbstractSerializationDatabase
Returns the next key greater than or equal to fromKey that corresponds to an object in this database. This method is called while holding this database's monitor.

Specified by:
doNextKey in class AbstractSerializationDatabase
Parameters:
fromKey - key from which to start the search
Returns:
the key of the next database object or -1, if no more database objects
Throws:
java.io.IOException - if an I/O error occurs

doRemoveObject

protected void doRemoveObject(long oldKey)
                       throws java.io.IOException
Description copied from class: AbstractSerializationDatabase
Removes the specified object from this database.

This method is called when a garbage collection finds the object unreachable. It is called while holding this database's monitor.

Specified by:
doRemoveObject in class AbstractSerializationDatabase
Parameters:
oldKey - keys of the object to remove from this database
Throws:
java.io.IOException - if an I/O error occurs

doOpen

protected void doOpen(boolean readOnly)
               throws java.io.IOException
Description copied from class: AbstractDatabase
Performs the action of open. This method is called inside open if this database is in an acceptable state. It has the same semantics as open.

Overrides:
doOpen in class AbstractSerializationDatabase
Parameters:
readOnly - true if database updates are not allowed
Throws:
java.io.IOException - if an I/O error occurs
See Also:
AbstractDatabase.open

Side of Software
Persistence Library 2.0

Copyright 2004-08 Side of Software (SOS). All rights reserved.