org.apache.jdo.impl.fostore
Class FOStoreDatabase

java.lang.Object
  extended byorg.apache.jdo.impl.fostore.FOStoreDatabase

class FOStoreDatabase
extends java.lang.Object

File/Object Store Database, using an underlying Btree implementation.

Author:
Dave Bristor

Field Summary
private static java.util.HashMap databaseMap
          We manage a map of pools of databases by database name.
private  DBInfo dbInfo
           
(package private) static org.apache.commons.logging.Log logger
          Logger
private static org.apache.jdo.util.I18NHelper msg
          I18N support.
private  int openConnections
          Count the number of connections open on this database.
private  org.apache.jdo.util.Pool pool
          Pool for this database.
private static int poolSize
           
private  java.util.HashMap provisionalCLIDs
           
private  java.util.HashMap provisionalOIDs
           
private  FOStoreBtreeStorage storage
           
 
Constructor Summary
(package private) FOStoreDatabase(java.lang.String name, boolean isNew)
          Create an FODatabase and create/open the files.
 
Method Summary
 void add(OID key, java.lang.Object value)
          Adds the specified value to values associated in this index with the specified key.
 void addConnection()
          Increment the openConnections to allow proper close when the last connection closes the database.
 void close()
          Decrement the open connections counter and close the database when it reaches zero.
private  void closeBtreeStorage(FOStoreBtreeStorage storage)
          Helper method to close a BtreeStorage.
static void closeDatabase(java.lang.String dbname)
           
 void commitChanges()
           
(package private) static Block createBlock(FOStoreInput in, int length)
           
private  FOStoreBtreeStorage createBtreeStorage(java.lang.String name, boolean isNew)
          Helper method to create a BtreeStorage.
private  void deleteFile(java.io.File file)
          Helper method to delete a file.
private  boolean existsFile(java.io.File file)
          Helper method to check whether a file exists.
 java.lang.Object get(OID key)
          Returns the value to which this index maps the specified key.
static FOStoreDatabase getDatabase(java.lang.String dbname, boolean create)
          Find an open database of the given name.
 DBInfo getDBInfo()
          Get the DBInfo for this database.
 java.lang.Object getIfExists(OID key)
          Returns the value to which this index maps the specified key or null if there is no value for this key.
 java.lang.String getName()
          Returns the unique name of the index in the Storage.
 CLID getRealCLIDFromProvisional(CLID provCLID)
          Provides a datastore CLID corresponding to the given provisional CLID.
(package private)  OID getRealOIDFromProvisional(OID pOID)
          Provides a datastore OID corresponding to the given provisional OID.
 java.util.Set keySet()
          Returns a set view of the keys contained in this index.
 void mapProvisionalCLIDToReal(CLID pCLID, CLID rCLID)
          Establishes a mapping in this database from provisional to real CLIDs.
(package private)  void mapProvisionalOIDToReal(OID pOID, OID rOID)
          Establishes a mapping in this database from provisional to real OIDs.
 boolean put(OID key, java.lang.Object value)
          Associates the specified value with the specified key in this index.
static void releaseDatabase(FOStoreDatabase db)
          Release the database for other connections to use.
 boolean remove(OID key)
          Removes all values assosiated in the index with specified key.
 void replace(OID key, java.lang.Object value)
          Replaces the original value associated with the specified key in this index with new value.
 void rollbackChanges()
           
private  void setPool(org.apache.jdo.util.Pool pool)
           
 void verifyUserPassword(java.lang.String user, long timestamp, byte[] secret)
          Verify that this user is authorized to use this database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

databaseMap

private static final java.util.HashMap databaseMap
We manage a map of pools of databases by database name.


poolSize

private static final int poolSize
See Also:
Constant Field Values

storage

private FOStoreBtreeStorage storage

provisionalCLIDs

private final java.util.HashMap provisionalCLIDs

provisionalOIDs

private final java.util.HashMap provisionalOIDs

openConnections

private int openConnections
Count the number of connections open on this database. When the last connection closes, then really close the database.


dbInfo

private DBInfo dbInfo

pool

private org.apache.jdo.util.Pool pool
Pool for this database.


msg

private static final org.apache.jdo.util.I18NHelper msg
I18N support.


logger

static final org.apache.commons.logging.Log logger
Logger

Constructor Detail

FOStoreDatabase

FOStoreDatabase(java.lang.String name,
                boolean isNew)
          throws FOStoreDatabaseException
Create an FODatabase and create/open the files.

Parameters:
name - name of database, which is used to name the files
isNew - true if the database is being created
Method Detail

getDatabase

public static FOStoreDatabase getDatabase(java.lang.String dbname,
                                          boolean create)
                                   throws java.lang.InterruptedException,
                                          FOStoreDatabaseException
Find an open database of the given name. If it is not already open, open it and put it into the pool.

Throws:
java.lang.InterruptedException
FOStoreDatabaseException

releaseDatabase

public static void releaseDatabase(FOStoreDatabase db)
                            throws java.lang.InterruptedException
Release the database for other connections to use.

Throws:
java.lang.InterruptedException

verifyUserPassword

public void verifyUserPassword(java.lang.String user,
                               long timestamp,
                               byte[] secret)
Verify that this user is authorized to use this database.


getDBInfo

public DBInfo getDBInfo()
Get the DBInfo for this database.


put

public boolean put(OID key,
                   java.lang.Object value)
            throws FOStoreDatabaseException
Associates the specified value with the specified key in this index.

Parameters:
key -
value -
Returns:
true if there was an item in this index that was associated with the key prior to this call
Throws:
FOStoreDatabaseException

replace

public void replace(OID key,
                    java.lang.Object value)
             throws FOStoreDatabaseException
Replaces the original value associated with the specified key in this index with new value. If no value was associated with this key prior to this call StorageBadRequestException is thrown.

Parameters:
key -
value -
Throws:
FOStoreDatabaseException

get

public java.lang.Object get(OID key)
                     throws FOStoreDatabaseException
Returns the value to which this index maps the specified key. StorageBadRequestException is thrown if there is no value for the key.

Parameters:
key -
Returns:
value associated with specified key
Throws:
FOStoreDatabaseException

getIfExists

public java.lang.Object getIfExists(OID key)
                             throws FOStoreDatabaseException
Returns the value to which this index maps the specified key or null if there is no value for this key.

Parameters:
key -
Returns:
value associated with specified key or null
Throws:
FOStoreDatabaseException

getName

public java.lang.String getName()
Returns the unique name of the index in the Storage.

Returns:
The name of this index.

keySet

public java.util.Set keySet()
                     throws FOStoreDatabaseException
Returns a set view of the keys contained in this index. Returned set is read only and may not be modified.

Returns:
keys contained in this index
Throws:
FOStoreDatabaseException

add

public void add(OID key,
                java.lang.Object value)
         throws FOStoreDatabaseException
Adds the specified value to values associated in this index with the specified key. If the index puts limit on number of values associated with one key and adding value would break this limit, it thorows StorageBadRequestException.

Parameters:
key -
value -
Throws:
FOStoreDatabaseException

remove

public boolean remove(OID key)
               throws FOStoreDatabaseException
Removes all values assosiated in the index with specified key.

Parameters:
key -
Returns:
true if this index changed as a result of this call
Throws:
FOStoreDatabaseException

commitChanges

public void commitChanges()
                   throws FOStoreDatabaseException
Throws:
FOStoreDatabaseException

addConnection

public void addConnection()
Increment the openConnections to allow proper close when the last connection closes the database.


close

public void close()
           throws FOStoreDatabaseException
Decrement the open connections counter and close the database when it reaches zero.

Throws:
FOStoreDatabaseException

closeDatabase

public static void closeDatabase(java.lang.String dbname)
                          throws FOStoreDatabaseException,
                                 java.lang.InterruptedException
Throws:
FOStoreDatabaseException
java.lang.InterruptedException

rollbackChanges

public void rollbackChanges()
                     throws FOStoreDatabaseException
Throws:
FOStoreDatabaseException

createBlock

static Block createBlock(FOStoreInput in,
                         int length)

mapProvisionalCLIDToReal

public void mapProvisionalCLIDToReal(CLID pCLID,
                                     CLID rCLID)
Establishes a mapping in this database from provisional to real CLIDs. The mapping lasts as long as the server is running, that is, it is not durable.

Parameters:
pCLID - A provisional CLID.
rCLID - The non-provisional, datastore CLID corresponding to provCLID.
Throws:
javax.jdo.JDOFatalException - Thrown if the given CLID is not provisional.

getRealCLIDFromProvisional

public CLID getRealCLIDFromProvisional(CLID provCLID)
Provides a datastore CLID corresponding to the given provisional CLID.

Parameters:
provCLID - A provisional CLID for which there
Returns:
A non-provisional, datastore CLID corresponding to provCLID, or null if the given provCLID is not mapped to a datastore CLID.
Throws:
javax.jdo.JDOFatalException - Thrown if the given CLID is not provisional.

mapProvisionalOIDToReal

void mapProvisionalOIDToReal(OID pOID,
                             OID rOID)
Establishes a mapping in this database from provisional to real OIDs. The mapping lasts as long as the server is running, that is, it is not durable.

Parameters:
pOID - A provisional OID.
rOID - The non-provisional, datastore OID corresponding to pOID.
Throws:
javax.jdo.JDOFatalException - Thrown if the given OID is not provisional.

getRealOIDFromProvisional

OID getRealOIDFromProvisional(OID pOID)
Provides a datastore OID corresponding to the given provisional OID.

Parameters:
pOID - A provisional OID for which there
Returns:
A non-provisional, datastore OID corresponding to pOID or null if the given pOID is not mapped to a datastore OID.
Throws:
javax.jdo.JDOFatalException - Thrown if the given OID is not provisional.

setPool

private void setPool(org.apache.jdo.util.Pool pool)

createBtreeStorage

private FOStoreBtreeStorage createBtreeStorage(java.lang.String name,
                                               boolean isNew)
                                        throws FOStoreDatabaseException,
                                               javax.jdo.JDOFatalUserException
Helper method to create a BtreeStorage. This method excutes the storage operation in a doPrivileged block and handles possible exceptions.

Parameters:
name - name of database, which is used to name the files
isNew - true if the database is being created
Returns:
new database
Throws:
FOStoreDatabaseException - wraps a StorageException thrown by the create call.
javax.jdo.JDOFatalUserException - wraps a possible SecurityException.

closeBtreeStorage

private void closeBtreeStorage(FOStoreBtreeStorage storage)
                        throws FOStoreDatabaseException
Helper method to close a BtreeStorage.

Parameters:
storage - the database to be closed
Throws:
FOStoreDatabaseException - wraps a StorageException thrown by the close call.

existsFile

private boolean existsFile(java.io.File file)
Helper method to check whether a file exists. This method delegates to File.exists and handles possible SecurityExceptions.

Parameters:
file - the file to be checked
Returns:
true if the specified file exists.

deleteFile

private void deleteFile(java.io.File file)
Helper method to delete a file. This method delegates to File.delete and handles possible SecurityExceptions.

Parameters:
file - the file to be deleted