Package org.mycore.datamodel.ifs2
Class MCRStore
java.lang.Object
org.mycore.datamodel.ifs2.MCRStore
- Direct Known Subclasses:
MCRFileStore
,MCRMetadataStore
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
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final boolean
Indicates ascending order when listing IDsprotected Path
The base directory containing the stored datastatic final boolean
Indicates descending order when listing IDsprotected String
The ID of the storeprotected int
The maximum length of IDsprotected int
The last ID assigned by this store.static final Logger
protected int
Offset to add to the maximum ID found in the store to build the new ID.protected String
The prefix of slot namesprotected int[]
The slot subdirectory layout, which is the number of digits used at each subdirectory level to build the filename.protected String
The suffix of slot names -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
delete
(int id) Deletes the data stored under the given ID from the storeboolean
exists
(int id) Returns true if data for the given ID is existing in the store.int
getID()
Returns the ID of this storeint
Returns the next free ID that can be used to store data.protected Path
getSlot
(int id) Returns the slot file object used to store data for the given id.protected MCRStore.MCRStoreConfig
protected void
Initializes a new store instanceprotected void
init
(MCRStore.MCRStoreConfig config) boolean
isEmpty()
listIDs
(boolean order) Lists all IDs currently used in the store, in ascending or descending orderprotected void
setStoreConfig
(MCRStore.MCRStoreConfig storeConfig)
-
Field Details
-
ASCENDING
public static final boolean ASCENDINGIndicates ascending order when listing IDs- See Also:
-
DESCENDING
public static final boolean DESCENDINGIndicates descending order when listing IDs- See Also:
-
id
The ID of the store -
baseDirectory
The base directory containing the stored data -
idLength
protected int idLengthThe maximum length of IDs -
slotLength
protected int[] slotLengthThe slot subdirectory layout, which is the number of digits used at each subdirectory level to build the filename. -
prefix
The prefix of slot names -
suffix
The suffix of slot names -
offset
protected int offsetOffset 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 lastIDThe last ID assigned by this store. -
LOGGER
-
-
Constructor Details
-
MCRStore
public MCRStore()
-
-
Method Details
-
delete
Deletes the data stored under the given ID from the store- Parameters:
id
- the ID of the document to be deleted- Throws:
IOException
-
exists
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
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
- Returns:
- all Ids of this store
-
listIDs
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
- Returns:
- the absolute path of the local base directory
-
getSlot
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
-
init
-
init
Initializes a new store instance -
setStoreConfig
-