Class Store

  • All Implemented Interfaces:
    StoreConstants

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

      • storeAccessLock

        public java.lang.Object storeAccessLock
    • Constructor Detail

      • Store

        public Store​(java.lang.String logFilename)
              throws java.io.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:
        java.io.IOException - if an error occurs
      • Store

        public Store​(java.lang.String logFilename,
                     boolean areHandlersEnabled)
              throws java.io.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:
        java.io.IOException - if an error occurs
      • Store

        public Store​(java.lang.String logFilename,
                     boolean areHandlersEnabled,
                     java.lang.String urid,
                     boolean useNIO)
              throws java.io.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:
        java.io.IOException - if an error occurs
    • Method Detail

      • addExtraDeleteAttribute

        public void addExtraDeleteAttribute​(java.lang.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 java.util.Set<java.lang.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​(java.lang.ClassLoader classLoader)
        Set the classLoader
        Parameters:
        classLoader - the classLoader to use
      • addClassTag

        public void addClassTag​(java.lang.String tag,
                                java.lang.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 java.lang.String getTagFromClass​(java.lang.Class<?> clazz)
        Returns the tag name binded with a specified class
        Parameters:
        clazz - the class
        Returns:
        the tag name for clazz
      • getClassFromTag

        public java.lang.Class<?> getClassFromTag​(java.lang.String tag)
                                           throws java.lang.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:
        java.lang.ClassNotFoundException - if an error occurs
      • getStorable

        public Storable getStorable​(java.lang.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​(java.lang.String id)
        Parameters:
        id - the storable id
        Returns:
        true if the storable is still registered
        Since:
        jcms-5.0.0
      • getVersionList

        public java.util.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 java.util.List<? extends Storable> getVersionList​(java.lang.String id)
        Get all the version of a given Storable ID
        Parameters:
        id - the ID of storable
        Returns:
        a list of Storable
      • getDeletedSet

        public java.util.TreeSet<? extends Storable> getDeletedSet​(java.lang.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​(java.io.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 boolean parseLog​(LogManagerHandler handler,
                                int 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
      • appendAndProcessSuffix

        public void appendAndProcessSuffix​(java.util.List<? extends LogEntry> logEntryList)
                                    throws java.io.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:
        java.io.IOException - if an error occurs
        Since:
        jcms-4.1
      • iterator

        public java.util.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 java.lang.String getUrid()
        Returns:
        the current urid value
        See Also:
        StampManager.getUrid()
      • setUrid

        public void setUrid​(java.lang.String urid)
        Set the current urid value
        Parameters:
        urid - the URID
        See Also:
        StampManager.setUrid(String)
      • 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(Stamp, boolean)
      • 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:
        StampManager.update(com.jalios.jstore.Stamp,boolean)
      • getStamp

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

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

        public SyncManager getSyncManager()
        Return the SyncManager
        Returns:
        the SyncManager
        Since:
        jcms-4.0.2
      • 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 java.io.IOException
        Create a storable, set storable id to stamp value.
        Parameters:
        storable - the storable to create.
        Throws:
        java.io.IOException - if an error occurs
      • create

        public void create​(Storable storable,
                           boolean overrideId)
                    throws java.io.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:
        java.io.IOException - if an error occurs
        Since:
        jcms-4.0
      • update

        public void update​(java.lang.String id,
                           java.util.Map<java.lang.String,​java.lang.String> attributes)
                    throws java.io.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:
        java.io.IOException - if an error occurs
      • update

        public void update​(Storable storable,
                           java.util.Map<java.lang.String,​java.lang.String> attributes)
                    throws java.io.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:
        java.io.IOException - if an error occurs
      • update

        public void update​(java.lang.String id,
                           Storable updated)
                    throws java.io.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:
        java.io.IOException - if an error occurs
        NoUpdateException - if an error occurs
      • update

        public void update​(Storable storable,
                           Storable updated)
                    throws java.io.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:
        java.io.IOException - if an error occurs
        NoUpdateException - on error, for example when given objects are same instance
      • delete

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

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

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

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

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

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

        public void generateLogFromMemory​(java.lang.String backupFilename)
                                   throws java.io.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:
        java.io.IOException - if an error occurs
      • printMemoryToLog

        public void printMemoryToLog​(java.io.OutputStream out)
                              throws java.lang.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:
        java.lang.Exception - if an error occurs
      • getLogCleaner

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

        public java.lang.String getLogFilename()
        Return the name of the log file.
        Returns:
        the name of the log file
      • getLoadReport

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

        public int 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
      • 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 int getCreationLineNumber​(java.lang.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​(java.io.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:
        LogManager.backupStore(File)
      • 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 java.util.Set<StoreListener> getStoreListeners​(boolean repeat)
      • getStoreClassListeners

        public java.util.Map<java.lang.Class<?>,​java.util.Set<StoreListener>> getStoreClassListeners​(boolean repeat)
      • addStoreListener

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

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

        public void removeStoreListener​(StoreListener listener)
      • removeStoreListener

        public void removeStoreListener​(StoreListener listener,
                                        java.lang.Class<?> clazz)
      • close

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