Interface DataStore

All Known Implementing Classes:
AbstractDataStore, AbstractSharedCachingDataStore, CachingDataStore, CachingFDS, CachingFileDataStore, DataStoreBlobStore, DbDataStore, DerbyDataStore, FileDataStore, MultiDataStore, OakFileDataStore

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 Details

    • 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 - if the data store could not be accessed
    • 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
    • getRecordFromReference

      DataRecord getRecordFromReference(String reference) throws DataStoreException
      Returns the record that matches the given binary reference. Returns null if the reference is invalid, for example if it points to a record that does not exist.
      Parameters:
      reference - binary reference
      Returns:
      matching record, or null
      Throws:
      DataStoreException - if the data store could not be accessed
    • 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 occurred
    • 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.