Class Store

java.lang.Object
com.jalios.jstore.Store
All Implemented Interfaces:
StoreConstants

public class Store extends Object implements StoreConstants
This class is the facade of JStore framework. It encapsulates all the sub-components involved for the object storage.
Author:
Olivier Dedieu <olivier.dedieu@jalios.com>
  • Field Details

    • DEFAULT_HANDLER_FLAG

      public static final boolean DEFAULT_HANDLER_FLAG
      See Also:
    • storeAccessLock

      public Object storeAccessLock
  • Constructor Details

    • Store

      public Store(String logFilename) throws IOException
      Create a new Store which does not support precompiled store handlers nor in-memory parsing.
      Parameters:
      logFilename - the name of the file which contains the log
      Throws:
      IOException - if an error occurs
    • Store

      public Store(String logFilename, boolean areHandlersEnabled) throws IOException
      Create a new Store which does not support precompiled store handlers.
      Parameters:
      logFilename - the name of the file which contains the log
      areHandlersEnabled - specify if the precompiled store handlers are supported.
      Throws:
      IOException - if an error occurs
    • Store

      public Store(String logFilename, boolean areHandlersEnabled, String urid, boolean useNIO) throws IOException
      Create a new Store
      Parameters:
      logFilename - the name of the file which contains the log
      areHandlersEnabled - specify if the precompiled store handlers are supported.
      urid - the URID
      useNIO - specify if the NIO must be used (faster store access)
      Throws:
      IOException - if an error occurs
  • Method Details

    • addExtraDeleteAttribute

      public void addExtraDeleteAttribute(String attName)
      Adds an attribute which will be stored when a storable is deleted.
      Parameters:
      attName - the attribute name
      Since:
      jcms-5.5.0
    • getExtraDeleteAttributeSet

      public Set<String> getExtraDeleteAttributeSet()
      Returns the list of attributes stored when a storable is deleted.
      Returns:
      the list of attributes stored when a storable is deleted.
      Since:
      jcms-5.5.0
    • setClassLoader

      public void setClassLoader(ClassLoader classLoader)
      Set the classLoader
      Parameters:
      classLoader - the classLoader to use
    • addClassTag

      public void addClassTag(String tag, Class<?> clazz)
      Binds a tag name with a Storable class. By default, the tag name of is the full name of a class, e.g. foo.bar.MyClass.
      Parameters:
      tag - the nam of the tag
      clazz - the class
    • getTagFromClass

      public String getTagFromClass(Class<?> clazz)
      Returns the tag name binded with a specified class
      Parameters:
      clazz - the class
      Returns:
      the tag name for clazz
    • getClassFromTag

      public Class<?> getClassFromTag(String tag) throws ClassNotFoundException
      Returns the class binded with a specified tag name If the class was not registered the class associated
      to the name is returned
      Parameters:
      tag - the tag name
      Returns:
      the class binded to the tag
      Throws:
      ClassNotFoundException - if an error occurs
    • getStorable

      public Storable getStorable(String id)
      Return the storable given its id
      Parameters:
      id - the storable id
      Returns:
      the storable bound with this id
    • isReferrenced

      public boolean isReferrenced(Storable storable)
      Parameters:
      storable - the storable to check
      Returns:
      true if there is exist at least one storable which references the given storable
    • isRegistered

      public boolean isRegistered(Storable storable)
      Parameters:
      storable - the storable to check
      Returns:
      true if the storable is still registered
      Since:
      jcms-5.0.0
    • isRegistered

      public boolean isRegistered(String id)
      Parameters:
      id - the storable id
      Returns:
      true if the storable is still registered
      Since:
      jcms-5.0.0
    • getVersionList

      public List<? extends Storable> getVersionList(Storable storable)
      Get all the version of a given Storable
      Parameters:
      storable - the storable
      Returns:
      a list of Storable
    • getVersionList

      public List<? extends Storable> getVersionList(String id)
      Get all the version of a given Storable ID
      Parameters:
      id - the ID of storable
      Returns:
      a list of Storable
    • getDeletedSet

      public TreeSet<? extends Storable> getDeletedSet(Class<?> clazz)
      Get the latest version of the deleted Storable for a given class.
      Parameters:
      clazz - the searched class
      Returns:
      a Set of Storable
    • generateDelta

      public int generateDelta(OutputStream out, Stamp startStamp, boolean includeStart) throws LogException
      Ouput in a given stream all the log operations having a stamp greater that the given one.
      Parameters:
      out - the outputstream to use to output the operations
      startStamp - the stamp to start the copy
      includeStart - true if the start stamp must be included
      Returns:
      the number of operations outputted
      Throws:
      LogException - if an error occurs
    • parseLog

      public void parseLog(LogManagerHandler handler) throws LogException
      Parse the store with the given handler
      Parameters:
      handler - the handler used to parse the store
      Throws:
      LogException - if an error occurs
      Since:
      jcms-4.1
    • parseLog

      public void parseLog(LogManagerHandler handler, Stamp stamp) throws LogException
      Parse the store with the given handler from the given stamp
      Parameters:
      handler - the handler used to parse the store
      stamp - the stamp to start the parsing
      Throws:
      LogException - if an error occurs
      Since:
      jcms-5.0.0
    • parseLog

      public void parseLog(LogManagerHandler handler, long startLine, boolean includeLogWork) throws LogException
      Parse the store with the given handler from the given stamp
      Parameters:
      handler - the handler used to parse the store
      startLine - the first line to start the parsing
      includeLogWork - if true include the logWork
      Throws:
      LogException - if an error occurs
      Since:
      jcms-11.0.1
    • parseLog

      public boolean parseLog(LogManagerHandler handler, long startLine)
      Parse the store with the given handler from the given line number
      Parameters:
      handler - the handler used to parse the store
      startLine - the line number to start the parsing
      Returns:
      false if an exception occures while parsing the log; true otherwise
      Since:
      jcms-5.0.0
    • replaceSuffix

      public void replaceSuffix(TreeSet<StorableLogEntry> newSuffix, LogEntry startLogEntry, boolean includeStart) throws IOException
      Parameters:
      newSuffix - The new suffix
      startLogEntry - the start logEntry
      includeStart - true if the startLogEntry must be included
      Throws:
      IOException - if an error occurs
      Since:
      jcms-4.1
      See Also:
    • appendAndProcessSuffix

      public void appendAndProcessSuffix(List<? extends LogEntry> logEntryList) throws IOException
      Appends the given LogEntries in the store.xml file and process each of them.
      Parameters:
      logEntryList - the list of logEntry. It assumes the logEntries are sorted according their stamps
      Throws:
      IOException - if an error occurs
      Since:
      jcms-4.1
    • stampExists

      public boolean stampExists(Stamp stamp)
      Parameters:
      stamp - the stamp
      Returns:
      true if the given stamp exists
      Since:
      jcms-10.0.8
    • moveOperations

      public long moveOperations(Stamp stamp, long expectedLineCount)
      Move the operations of store-work.xml to the most recent store-prefix-n.xml. This method is dedicated for logDir.
      Parameters:
      stamp - move all the operations before this stamps, and also the operation with this stamp.
      expectedLineCount - the exepected line count to move
      Returns:
      the number of lines moved (-1 if an error occured)
      Since:
      jcms-10.0.8
    • iterator

      public Iterator<Storable> iterator()
      Return an iterator on the storables registered in the swizzler
      Returns:
      the storable iterator.
    • getSize

      public int getSize()
      Return the size of the store.
      Returns:
      the size of the store.
    • getState

      public int getState()
      Return the current state of the store (see StoreConstants).
      Returns:
      the current state
    • getUrid

      public String getUrid()
      Returns:
      the current urid value
      See Also:
    • setUrid

      public void setUrid(String urid)
      Set the current urid value
      Parameters:
      urid - the URID
      See Also:
    • updateStamp

      public void updateStamp(Stamp stamp)
      Update the current stamp value (and the progress table)
      Parameters:
      stamp - the stamp to be added
      Since:
      jcms-4.0
      See Also:
    • updateStamp

      public void updateStamp(Stamp stamp, boolean updatePT)
      Update the current stamp value
      Parameters:
      stamp - the stamp to be added
      updatePT - if true use this stamp to update the progress table
      Since:
      jcms-5.0.6
      See Also:
    • getStamp

      public Stamp getStamp()
      Return a new stamp. Ensures their strict monotonicity.
      Returns:
      a new stamp
      Since:
      jcms-4.0.2
      See Also:
    • getProgressTable

      public StampTable getProgressTable()
      Return the progressTable
      Returns:
      the map of greatest stamp
      See Also:
    • getProgressStamp

      public Stamp getProgressStamp()
      Return the greatest stamp of this urid
      Returns:
      a Stamp
      See Also:
    • getProgressStamp

      public Stamp getProgressStamp(String urid)
      Return the greatest stamp of the given urid
      Parameters:
      urid - the urid
      Returns:
      a Stamp
      See Also:
    • getSyncManager

      public SyncManager getSyncManager()
      Return the SyncManager
      Returns:
      the SyncManager
      Since:
      jcms-4.0.2
    • load

      public void load() throws LogException
      Load and process the log
      Throws:
      LogException - if an error occurs
    • load

      public void load(boolean processStorable, boolean processInner) throws LogException
      Load and process the log
      Parameters:
      processStorable - if true the storable operations are processed. If false only the stamps information are processed.
      processInner - if true the storable operations are processed. If false only the stamps information are processed.
      Throws:
      LogException - if an error occurs
      Since:
      jcms-4.0.2
    • processLogEntry

      public void processLogEntry(LogEntry logEntry)
    • processInnerLogEntry

      public void processInnerLogEntry(InnerLogEntry logEntry)
    • processStorableLogEntry

      public void processStorableLogEntry(StorableLogEntry sle)
    • create

      public void create(Storable storable) throws IOException
      Create a storable, set storable id to stamp value.
      Parameters:
      storable - the storable to create.
      Throws:
      IOException - if an error occurs
    • create

      public void create(Storable storable, boolean overrideId) throws IOException
      Create a storable, if overrideId is false and storable have an id then do not override id. The storable lus not have been swizzled.
      Use with care the overrideId parameter.
      Parameters:
      storable - the storable
      overrideId - if overrideId is false and storable have an id then do not override id
      Throws:
      IOException - if an error occurs
      Since:
      jcms-4.0
    • update

      public void update(String id, Map<String,String> attributes) throws IOException
      Update a storable. Perform the update operation on all elements of the map even if the attribute value is not updated.
      Parameters:
      id - the id of the storable to update
      attributes - the map that contains the new attributes values
      Throws:
      IOException - if an error occurs
    • update

      public void update(Storable storable, Map<String,String> attributes) throws IOException
      Update a storable. Perform the update operation on all elements of the map even if the attribute value is not updated.
      Parameters:
      storable - the storable to update
      attributes - the map that contains the new attributes values
      Throws:
      IOException - if an error occurs
    • update

      public void update(String id, Storable updated) throws IOException, NoUpdateException
      Update a storable. The stored update only concerns fields that are differents (i.e. not the same object) between storable and updated.
      Parameters:
      id - the id of the storable to update
      updated - the updated storable
      Throws:
      IOException - if an error occurs
      NoUpdateException - if an error occurs
    • update

      public void update(Storable storable, Storable updated) throws IOException, NoUpdateException
      Update a storable. The stored update only concerns fields that are differents (i.e. not the same object) between storable and updated.
      Parameters:
      storable - the storable to update
      updated - the updated storable
      Throws:
      IOException - if an error occurs
      NoUpdateException - on error, for example when given objects are same instance
    • delete

      public void delete(Storable storable) throws IOException
      Delete a storable (even if references remain on it).
      Parameters:
      storable - the storable to delete
      Throws:
      IOException - if an error occurs
    • delete

      public void delete(Storable storable, boolean force) throws IOException
      Delete a storable.
      Parameters:
      storable - the storable to delete
      force - if true the referenced storable attributes are deleted
      Throws:
      IOException - if an error occurs
    • getMilestoneList

      public List<InnerLogEntry> getMilestoneList()
      Returns the list of milestones.
      Returns:
      the list of milestones.
      Since:
      jcms-5.5.0
    • appendMilestone

      public void appendMilestone(String text) throws IOException
      Appends a milestone in the store.
      Parameters:
      text - the text of the milestone.
      Throws:
      IOException - if an error occurs
      Since:
      jcms-5.5.0
    • appendMilestone

      public void appendMilestone(Map<String,String> map) throws IOException
      Appends a milestone in the store.
      Parameters:
      map - the map of attributes.
      Throws:
      IOException - if an error occurs
      Since:
      jcms-5.5.0
    • appendSync

      public void appendSync(Date date) throws IOException
      Appends a sync tag in the store.
      Parameters:
      date - the date of the sync.
      Throws:
      IOException - if an error occurs
      Since:
      jcms-5.5.0
    • generateLogFromMemory

      public void generateLogFromMemory(String backupFilename) throws IOException
      Cleans the log. The current log file is remplaced by a new one which contains the result of printCleanedLog method. If a backup filename is provided (i.e. not null), the current log file is copy into before to be cleaned.
      Parameters:
      backupFilename - the name of the file to backup the current log
      Throws:
      IOException - if an error occurs
    • printMemoryToLog

      public void printMemoryToLog(OutputStream out) throws Exception
      Prints a cleaned version of the log. All operations on deleted storable are removed. All update operations are integrated in a new creation operations (except cycling storable references which are resolved in a second update step).
      Parameters:
      out - the OutputStream in which to print the cleaned log
      Throws:
      Exception - if an error occurs
    • getLogCleaner

      public LogCleaner getLogCleaner()
      Returns the LogCleaner.
      Returns:
      the LogCleaner.
      Since:
      jcms-5.5.0
    • getLogFilename

      public String getLogFilename()
      Return the name of the log file.
      Returns:
      the name of the log file.
    • getLogDirectory

      public File getLogDirectory()
      Return the name of the log directory.
      Returns:
      the name of the log directory.
      Since:
      jcms-10.0.8
    • isLogDirectory

      public boolean isLogDirectory()
      Returns:
      true if the log is managed with a directory.
      Since:
      jcms-10.0.8
    • getLogFileList

      public List<File> getLogFileList()
      Returns:
      the list of files in the log directory.
      Since:
      jcms-10.0.8
    • getLogFile

      public File getLogFile()
      Returns:
      the log file.
      Since:
      jcms-10.0.8
    • getLogWorkFile

      public File getLogWorkFile()
    • getLatestLogPrefixFile

      public File getLatestLogPrefixFile()
    • getPrefixLineCount

      public long getPrefixLineCount()
      Returns:
      the number of lines in all store prefix files.
      Since:
      jcms-10.0.8
    • getLogDirectoryFileLineCount

      public long getLogDirectoryFileLineCount(File file)
      Parameters:
      file - a file of the log directory
      Returns:
      the number of lines of the given file.
      Since:
      jcms-10.0.8
    • getLogWorkStartLine

      public long getLogWorkStartLine()
      Returns:
      the start line number of the log work file.
      Since:
      jcms-10.0.8
    • refreshLogDirectory

      public void refreshLogDirectory() throws LogException
      Throws:
      LogException
    • refreshLogFile

      public void refreshLogFile() throws LogException
      Throws:
      LogException
    • setLogDirectoryFileMaxSize

      public void setLogDirectoryFileMaxSize(long logDirFileMaxSize)
    • getLogDirectoryFileMaxSize

      public long getLogDirectoryFileMaxSize()
    • getLoadReport

      public LoadReport getLoadReport()
      Return the load report
      Returns:
      a LoadReport instance
    • getStampLineNumber

      public long getStampLineNumber(Stamp stamp)
      Returns the line number in the store file of the given stamp.
      Parameters:
      stamp - the stamp to get the line number
      Returns:
      the line number (starts at 0)
      Since:
      jcms-5.0.1
    • getStampLineNumberInLogWork

      public long getStampLineNumberInLogWork(Stamp stamp)
      Returns the line number in the log work file for the given stamp.
      Parameters:
      stamp - the stamp.
      Returns:
      the line number in the log work file for the given stamp.
      Since:
      jcms-10.0.8
    • verifyStampLineMap

      public boolean verifyStampLineMap()
      Verify if the stamps are correctly indexed. Prints the first bad indexed stamp in the log.
      Returns:
      true if all the stamps are correctly indexed.
      Since:
      jcms-5.0.5
    • verifyLastStampIndex

      public boolean verifyLastStampIndex()
      Verify if the last (highest) stamp is correctly indexed.
      Returns:
      true if the latest stamps are correctly indexed.
    • getCreationLineNumber

      public long getCreationLineNumber(String id)
      Returns the line number in the store file of the creation. entry of the given storable
      Parameters:
      id - the id of the storable
      Returns:
      the line number (starts at 0)
      Since:
      jcms-5.0.1
    • backupStore

      public boolean backupStore(File backupFile)
      Backup the store.
      Parameters:
      backupFile - the backup file.
      Returns:
      true if the store has been successfully backuped.
      Since:
      jcms-5.7.0
      See Also:
    • setReplaceSuffixLimit

      public void setReplaceSuffixLimit(int replaceSuffixLimit)
      A store suffix replacement starting before the limit will be rejected.
      Parameters:
      replaceSuffixLimit - the limit (in number of lines).
      Since:
      jcms-5.7.4
    • getStoreListeners

      public Set<StoreListener> getStoreListeners(boolean repeat)
    • getStoreClassListeners

      public Map<Class<?>,Set<StoreListener>> getStoreClassListeners(boolean repeat)
    • addStoreListener

      public void addStoreListener(StoreListener listener, boolean repeat)
    • addStoreListener

      public void addStoreListener(StoreListener listener, Class<?> clazz, boolean repeat)
    • removeStoreListener

      public void removeStoreListener(StoreListener listener)
    • removeStoreListener

      public void removeStoreListener(StoreListener listener, Class<?> clazz)
    • close

      public void close()
      Close all Store resources when ending.