org.mycore.datamodel.ifs2
Class MCRStore

java.lang.Object
  extended by 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 Summary
static boolean ASCENDING
          Indicates ascending order when listing IDs
static boolean DESCENDING
          Indicates descending order when listing IDs
protected  File dir
          The base directory containing the stored data
protected  String id
          The ID of the store
protected  int idLength
          The maximum length of IDs
protected  int lastID
          The last ID assigned by this store.
protected  int offset
          Offset to add to the maximum ID found in the store to build the new ID.
protected  String prefix
          The prefix of slot names
protected  int[] slotLength
          The slot subdirectory layout, which is the number of digits used at each subdirectory level to build the filename.
protected static HashMap<String,MCRStore> stores
          Map of defined stores, where store ID is the map key.
protected  String suffix
          The suffix of slot names
 
Constructor Summary
MCRStore()
           
 
Method Summary
(package private)  void delete(org.apache.commons.vfs.FileObject fo)
          Deletes the data stored in the given file object from the store
 void delete(int id)
          Deletes the data stored under the given ID from the store
 boolean exists(int id)
          Returns true if data for the given ID is existing in the store.
(package private)  String getBaseDir()
          Returns the absolute path of the local base directory
 int getHighestStoredID()
           
 String getID()
          Returns the ID of this store
 int getNextFreeID()
          Returns the next free ID that can be used to store data.
(package private)  org.apache.commons.vfs.FileObject getSlot(int ID)
          Returns the slot file object used to store data for the given ID.
(package private)  String getSlotPath(int ID)
          Returns the relative path used to store data for the given ID within the store base directory
(package private)  String[] getSlotPaths(int ID)
          Returns the paths of all subdirectories and the slot itself used to store data for the given ID relative to the store base directory
protected static MCRStore getStore(String ID)
          Returns the store with the given ID
protected  void init(String id)
          Initializes a new store instance
 Iterator<Integer> listIDs(boolean order)
          Lists all IDs currently used in the store, in ascending or descending order
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stores

protected static HashMap<String,MCRStore> stores
Map of defined stores, where store ID is the map key.


id

protected String id
The ID of the store


dir

protected File dir
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.


ASCENDING

public static final boolean ASCENDING
Indicates ascending order when listing IDs

See Also:
Constant Field Values

DESCENDING

public static final boolean DESCENDING
Indicates descending order when listing IDs

See Also:
Constant Field Values
Constructor Detail

MCRStore

public MCRStore()
Method Detail

getStore

protected static MCRStore getStore(String ID)
Returns the store with the given ID

Parameters:
ID - the ID of the store

init

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


getID

public String getID()
Returns the ID of this store


getBaseDir

String getBaseDir()
Returns the absolute path of the local base directory

Returns:
the base directory storing the data

getSlot

org.apache.commons.vfs.FileObject getSlot(int ID)
                                    throws Exception
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:
Exception

getSlotPath

String getSlotPath(int ID)
Returns the relative path used to store data for the given ID within the store base directory

Parameters:
ID - the ID of the data
Returns:
the relative path storing that data

getSlotPaths

String[] getSlotPaths(int ID)
Returns the paths of all subdirectories and the slot itself used to store data for the given ID relative to the store base directory

Parameters:
ID - the ID of the data
Returns:
the directory and file names of the relative path storing that data

exists

public boolean exists(int id)
               throws Exception
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:
Exception

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

getHighestStoredID

public int getHighestStoredID()

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:
ASCENDING, DESCENDING

delete

public void delete(int id)
            throws Exception
Deletes the data stored under the given ID from the store

Parameters:
id - the ID of the document to be deleted
Throws:
Exception

delete

void delete(org.apache.commons.vfs.FileObject fo)
      throws Exception
Deletes the data stored in the given file object from the store

Parameters:
fo - the file object to be deleted
Throws:
Exception