Class MCRStore

java.lang.Object
org.mycore.datamodel.ifs2.MCRStore
Direct Known Subclasses:
MCRFileStore, MCRMetadataStore

public abstract class MCRStore extends Object
Stores metadata files or file collections containing files and directories in a persistent store implemented using a local filesystem. For better filesystem performance, the store can build slot subdirectories (containing other subdirectories and so on) so that not all objects are stored in the same filesystem directory. Directories containing a very large number of files typically show bad performance. The slot layout of the store defines the usage of subdirectories within the base directory. A layout of "8" would mean no subdirectories will be used, the maximum ID size is 8 digits, and therefore up to 99999999 objects can be stored all in the same base directory. A layout of "2-2-4" would mean data is stored using two levels of subdirectories, where the first subdirectory contains up to 100 (00-99) subdirectories, the second subdirectory level below contains up to 100 subdirectories, too, and below the data is stored, with up to 10000 data objects in the subdirectory. Using this slot layout, the data of ID 10485 would be stored in the file object "/00/01/00010485", for example. Using layout "4-2-2", data would be stored in "/0001/04/00010485", and so on. The slot file name itself may optionally have a prefix and suffix. With prefix "derivate-", the slot name would be "derivate-00010485". With prefix "DocPortal_document_" and suffix ".xml", the slot name would be "DocPortal_document_00010485.xml" for example. MCR.IFS2.Store.ID.Class=org.mycore.datamodel.ifs2.MCRFileStore MCR.IFS2.Store.ID.BaseDir=/foo/bar MCR.IFS2.Store.ID.SlotLayout=4-2-2
Author:
Frank Lützenkirchen
  • Field Details

    • ASCENDING

      public static final boolean ASCENDING
      Indicates ascending order when listing IDs
      See Also:
    • DESCENDING

      public static final boolean DESCENDING
      Indicates descending order when listing IDs
      See Also:
    • id

      protected String id
      The ID of the store
    • baseDirectory

      protected Path baseDirectory
      The base directory containing the stored data
    • idLength

      protected int idLength
      The maximum length of IDs
    • slotLength

      protected int[] slotLength
      The slot subdirectory layout, which is the number of digits used at each subdirectory level to build the filename.
    • prefix

      protected String prefix
      The prefix of slot names
    • suffix

      protected String suffix
      The suffix of slot names
    • offset

      protected int offset
      Offset to add to the maximum ID found in the store to build the new ID. This is normally 1, but initially higher to avoid reassigning the same ID after system restarts. Consider the following example: 1) User creates new document, ID assigned is 10. 2) User deletes document 10. 3) Web application is restarted. 4) User creates new document, ID assigned is 20. If offset would always be 1, ID assigned would have been 10 again, and that is not nice, because we can not distinguish the two creates easily.
    • lastID

      protected int lastID
      The last ID assigned by this store.
    • LOGGER

      public static final Logger LOGGER
  • Constructor Details

    • MCRStore

      public MCRStore()
  • Method Details

    • delete

      public void delete(int id) throws IOException
      Deletes the data stored under the given ID from the store
      Parameters:
      id - the ID of the document to be deleted
      Throws:
      IOException
    • exists

      public boolean exists(int id) throws IOException
      Returns true if data for the given ID is existing in the store.
      Parameters:
      id - the ID of the data
      Returns:
      true, if data for the given ID is existing in the store.
      Throws:
      IOException
    • getHighestStoredID

      public int getHighestStoredID()
    • getID

      public String getID()
      Returns the ID of this store
    • getNextFreeID

      public int getNextFreeID()
      Returns the next free ID that can be used to store data. Call as late as possible to avoid that another process, for example from batch import, in the meantime already used that ID.
      Returns:
      the next free ID that can be used to store data
    • isEmpty

      public boolean isEmpty()
    • getStoredIDs

      public IntStream getStoredIDs()
      Returns:
      all Ids of this store
    • listIDs

      public Iterator<Integer> listIDs(boolean order)
      Lists all IDs currently used in the store, in ascending or descending order
      Parameters:
      order - the order in which IDs should be returned.
      Returns:
      all IDs currently used in the store
      See Also:
    • getBaseDirectory

      public Path getBaseDirectory()
      Returns:
      the absolute path of the local base directory
    • getSlot

      protected Path getSlot(int id) throws IOException
      Returns the slot file object used to store data for the given id. This may be a file or directory, depending on the subclass of MCRStore that is used.
      Parameters:
      id - the id of the data
      Returns:
      the file object storing that data
      Throws:
      IOException
    • getStoreConfig

      protected MCRStore.MCRStoreConfig getStoreConfig()
    • init

      protected void init(MCRStore.MCRStoreConfig config)
    • init

      protected void init(String id)
      Initializes a new store instance
    • setStoreConfig

      protected void setStoreConfig(MCRStore.MCRStoreConfig storeConfig)