org.apache.jackrabbit.core.data
Interface DataStore

All Known Implementing Classes:
DbDataStore, DerbyDataStore, FileDataStore

public interface DataStore

Append-only store for binary streams. A data store consists of a number of identifiable data records that each contain a distinct binary stream. New binary streams can be added to the data store, but existing streams are never removed or modified.

A data store should be fully thread-safe, i.e. it should be possible to add and access data records concurrently. Optimally even separate processes should be able to concurrently access the data store with zero interprocess synchronization.


Method Summary
 DataRecord addRecord(InputStream stream)
          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<DataIdentifier> getAllIdentifiers()
          Get all identifiers.
 int getMinRecordLength()
          Get the minimum size of an object that should be stored in this data store.
 DataRecord getRecord(DataIdentifier identifier)
          Returns the identified data record.
 DataRecord getRecordIfStored(DataIdentifier identifier)
          Check if a record for the given identifier exists, and return it if yes.
 void init(String homeDir)
          Initialized the data store
 void updateModifiedDateOnAccess(long before)
          From now on, update the modified date of an object even when accessing it.
 

Method Detail

getRecordIfStored

DataRecord getRecordIfStored(DataIdentifier identifier)
                             throws DataStoreException
Check if a record for the given identifier exists, and return it if yes. If no record exists, this method returns null.

Parameters:
identifier - data identifier
Returns:
the record if found, and null if not
Throws:
DataStoreException

getRecord

DataRecord getRecord(DataIdentifier identifier)
                     throws DataStoreException
Returns the identified data record. The given identifier should be the identifier of a previously saved data record. Since records are never removed, there should never be cases where the identified record is not found. Abnormal cases like that are treated as errors and handled by throwing an exception.

Parameters:
identifier - data identifier
Returns:
identified data record
Throws:
DataStoreException - if the data store could not be accessed, or if the given identifier is invalid

addRecord

DataRecord addRecord(InputStream stream)
                     throws DataStoreException
Creates a new data record. The given binary stream is consumed and a binary record containing the consumed stream is created and returned. If the same stream already exists in another record, then that record is returned instead of creating a new one.

The given stream is consumed and not closed by this method. It is the responsibility of the caller to close the stream. A typical call pattern would be:

     InputStream stream = ...;
     try {
         record = store.addRecord(stream);
     } finally {
         stream.close();
     }
 

Parameters:
stream - binary stream
Returns:
data record that contains the given stream
Throws:
DataStoreException - if the data store could not be accessed

updateModifiedDateOnAccess

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.

Parameters:
before - - update the modified date to the current time if it is older than this value

deleteAllOlderThan

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

Parameters:
min - the minimum time
Returns:
the number of data records deleted
Throws:
DataStoreException

getAllIdentifiers

Iterator<DataIdentifier> getAllIdentifiers()
                                           throws DataStoreException
Get all identifiers.

Returns:
an iterator over all DataIdentifier objects
Throws:
DataStoreException - if the list could not be read

init

void init(String homeDir)
          throws RepositoryException
Initialized the data store

Parameters:
homeDir - the home directory of the repository
Throws:
RepositoryException

getMinRecordLength

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.

Returns:
the minimum size in bytes

close

void close()
           throws DataStoreException
Close the data store

Throws:
DataStoreException - if a problem occured

clearInUse

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.



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