org.apache.jackrabbit.core.data
Class FileDataStore

java.lang.Object
  extended by org.apache.jackrabbit.core.data.FileDataStore
All Implemented Interfaces:
DataStore

public class FileDataStore
extends Object
implements DataStore

Simple file-based data store. Data records are stored as normal files named using a message digest of the contained binary stream. Configuration:

If the directory is not set, the directory <repository home>/repository/datastore is used.

A three level directory structure is used to avoid placing too many files in a single directory. The chosen structure is designed to scale up to billions of distinct records.

This implementation relies on the underlying file system to support atomic O(1) move operations with File.renameTo(File).


Constructor Summary
FileDataStore()
          Creates a uninitialized data store.
 
Method Summary
 DataRecord addRecord(InputStream input)
          Creates a new data record.
 void clearInUse()
          Clear the in-use list.
 void close()
          Close the data store
 int deleteAllOlderThan(long min)
          Delete objects that have a modified date older than the specified date.
 Iterator getAllIdentifiers()
          Get all identifiers.
 int getMinRecordLength()
          Get the minimum size of an object that should be stored in this data store.
 String getPath()
          Get the name of the directory where this data store keeps the files.
 DataRecord getRecord(DataIdentifier identifier)
          Returns the record with the given identifier.
 void init(String homeDir)
          Initialized the data store.
 void setMinRecordLength(int minRecordLength)
          Set the minimum object length.
 void setPath(String directoryName)
          Set the name of the directory where this data store keeps the files.
 void updateModifiedDateOnAccess(long before)
          From now on, update the modified date of an object even when accessing it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileDataStore

public FileDataStore()
Creates a uninitialized data store.

Method Detail

init

public void init(String homeDir)
Initialized the data store. If the path is not set, <repository home>/repository/datastore is used. This directory is automatically created if it does not yet exist.

Specified by:
init in interface DataStore
Parameters:
config - the repository configuration

getRecord

public DataRecord getRecord(DataIdentifier identifier)
Returns the record with the given identifier. Note that this method performs no sanity checks on the given identifier. It is up to the caller to ensure that only identifiers of previously created data records are used.

Specified by:
getRecord in interface DataStore
Parameters:
identifier - data identifier
Returns:
identified data record

addRecord

public DataRecord addRecord(InputStream input)
                     throws DataStoreException
Creates a new data record. The stream is first consumed and the contents are saved in a temporary file and the SHA-1 message digest of the stream is calculated. If a record with the same SHA-1 digest (and length) is found then it is returned. Otherwise the temporary file is moved in place to become the new data record that gets returned.

Specified by:
addRecord in interface DataStore
Parameters:
input - binary stream
Returns:
data record that contains the given stream
Throws:
DataStoreException - if the record could not be created

updateModifiedDateOnAccess

public void updateModifiedDateOnAccess(long before)
From now on, update the modified date of an object even when accessing it. Usually, the modified date is only updated when creating a new object, or when a new link is added to an existing object. When this setting is enabled, even getLength() will update the modified date.

Specified by:
updateModifiedDateOnAccess in interface DataStore
Parameters:
before - - update the modified date to the current time if it is older than this value

deleteAllOlderThan

public int deleteAllOlderThan(long min)
Delete objects that have a modified date older than the specified date.

Specified by:
deleteAllOlderThan in interface DataStore
Parameters:
min - the minimum time
Returns:
the number of data records deleted

getAllIdentifiers

public Iterator getAllIdentifiers()
Get all identifiers.

Specified by:
getAllIdentifiers in interface DataStore
Returns:
an iterator over all DataIdentifier objects

clearInUse

public void clearInUse()
Clear the in-use list. This is only used for testing to make the the garbage collection think that objects are no longer in use.

Specified by:
clearInUse in interface DataStore

getPath

public String getPath()
Get the name of the directory where this data store keeps the files.

Returns:
the full path name

setPath

public void setPath(String directoryName)
Set the name of the directory where this data store keeps the files.

Parameters:
path - the full path name

getMinRecordLength

public int getMinRecordLength()
Get the minimum size of an object that should be stored in this data store. Depending on the overhead and configuration, each store may return a different value.

Specified by:
getMinRecordLength in interface DataStore
Returns:
the minimum size

setMinRecordLength

public void setMinRecordLength(int minRecordLength)
Set the minimum object length.

Parameters:
minRecordLength - the length

close

public void close()
Close the data store

Specified by:
close in interface DataStore


Copyright © 2004-2008 The Apache Software Foundation. All Rights Reserved.