com.jalios.jstore
Class Store

java.lang.Object
  extended by 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.

Version:
$Revision: 27753 $
Author:
Olivier Dedieu

Field Summary
static boolean DEFAULT_HANDLER_FLAG
           
static String REVISION
           
 Object storeAccessLock
           
 
Fields inherited from interface com.jalios.jstore.StoreConstants
ARRAY_FLAG, CLEANING_STATE, COLLECTION_FLAG, CREATE_OP, DELETE_OP, IDLE_STATE, INNER_LOGS, INNER_MILESTONE, INNER_PREFIX, INNER_SYNC, ITEM_ESCAPE_CHAR, ITEM_SEPARATOR, LOADING_STATE, MAP_ASSIGN, MAP_CHARS_TO_ESCAPE, MAP_CLASS_SEPARATOR, MAP_FLAG, NAMESPACE, SH_SUFFIX, STORING_STATE, UPDATE_OP
 
Constructor Summary
Store(String logFilename)
          Create a new Store which does not support precompiled store handlers nor in-memory parsing.
Store(String logFilename, boolean areHandlersEnabled)
          Create a new Store which does not support precompiled store handlers.
Store(String logFilename, boolean areHandlersEnabled, String urid, boolean useNIO)
          Create a new Store
 
Method Summary
 void addClassTag(String tag, Class<?> clazz)
          Binds a tag name with a Storable class.
 void addExtraDeleteAttribute(String attName)
          Adds an attribute which will be stored when a storable is deleted.
 void addStoreListener(StoreListener listener, boolean repeat)
           
 void addStoreListener(StoreListener listener, Class<?> clazz, boolean repeat)
           
 void appendAndProcessSuffix(List<? extends LogEntry> logEntryList)
          Appends the given LogEntries in the store.xml file and process each of them.
 void appendMilestone(Map<String,String> map)
          Appends a milestone in the store.
 void appendMilestone(String text)
          Appends a milestone in the store.
 void appendSync(Date date)
          Appends a sync tag in the store.
 boolean backupStore(File backupFile)
          Backup the store.
 void close()
          Close all Store resources when ending.
 void create(Storable storable)
          Create a storable, set storable id to stamp value.
 void create(Storable storable, boolean overrideId)
          Create a storable, if overrideId is false and storable have an id then do not override id.
 void delete(Storable storable)
          Delete a storable (even if references remain on it).
 void delete(Storable storable, boolean force)
          Delete a storable.
 int generateDelta(OutputStream out, Stamp startStamp, boolean includeStart)
          Ouput in a given stream all the log operations having a stamp greater that the given one.
 void generateLogFromMemory(String backupFilename)
          Cleans the log.
 Class<?> getClassFromTag(String tag)
          Returns the class binded with a specified tag name If the class was not registered the class associated
to the name is returned
 int getCreationLineNumber(String id)
          Returns the line number in the store file of the creation.
 TreeSet<? extends Storable> getDeletedSet(Class<?> clazz)
          Get the latest version of the deleted Storable for a given class.
 Set<String> getExtraDeleteAttributeSet()
          Returns the list of attributes stored when a storable is deleted.
 LoadReport getLoadReport()
          Return the load report
 LogCleaner getLogCleaner()
          Returns the LogCleaner.
 String getLogFilename()
          Return the name of the log file.
 List<InnerLogEntry> getMilestoneList()
          Returns the list of milestones.
 Stamp getProgressStamp()
          Return the greatest stamp of this urid
 Stamp getProgressStamp(String urid)
          Return the greatest stamp of the given urid
 StampTable getProgressTable()
          Return the progressTable
 int getSize()
          Return the size of the store.
 Stamp getStamp()
          Return a new stamp.
 int getStampLineNumber(Stamp stamp)
          Returns the line number in the store file of the given stamp.
 int getState()
          Return the current state of the store (see StoreConstants).
 Storable getStorable(String id)
          Return the storable given its id
 Map<Class<?>,Set<StoreListener>> getStoreClassListeners(boolean repeat)
           
 Set<StoreListener> getStoreListeners(boolean repeat)
           
 SyncManager getSyncManager()
          Return the SyncManager
 String getTagFromClass(Class<?> clazz)
          Returns the tag name binded with a specified class
 String getUrid()
           
 List<? extends Storable> getVersionList(Storable storable)
          Get all the version of a given Storable
 List<? extends Storable> getVersionList(String id)
          Get all the version of a given Storable ID
 boolean isReferrenced(Storable storable)
           
 boolean isRegistered(Storable storable)
           
 boolean isRegistered(String id)
           
 Iterator<Storable> iterator()
          Return an iterator on the storables registered in the swizzler
 void load()
          Load and process the log
 void load(boolean processStorable, boolean processInner)
          Load and process the log
 void parseLog(LogManagerHandler handler)
          Parse the store with the given handler
 boolean parseLog(LogManagerHandler handler, int startLine)
          Parse the store with the given handler from the given line number
 void parseLog(LogManagerHandler handler, Stamp stamp)
          Parse the store with the given handler from the given stamp
 void printMemoryToLog(OutputStream out)
          Prints a cleaned version of the log.
 void processInnerLogEntry(InnerLogEntry logEntry)
           
 void processLogEntry(LogEntry logEntry)
           
 void processStorableLogEntry(StorableLogEntry storableLog)
           
 void removeStoreListener(StoreListener listener)
           
 void removeStoreListener(StoreListener listener, Class<?> clazz)
           
 void replaceSuffix(TreeSet<StorableLogEntry> newSuffix, LogEntry startLogEntry, boolean includeStart)
           
 void setClassLoader(ClassLoader classLoader)
          Set the classLoader
 void setReplaceSuffixLimit(int replaceSuffixLimit)
          A store suffix replacement starting before the limit will be rejected.
 void setUrid(String urid)
          Set the current urid value
 void update(Storable storable, Map<String,String> attributes)
          Update a storable.
 void update(Storable storable, Storable updated)
          Update a storable.
 void update(String id, Map<String,String> attributes)
          Update a storable.
 void update(String id, Storable updated)
          Update a storable.
 void updateStamp(Stamp stamp)
          Update the current stamp value (and the progress table)
 void updateStamp(Stamp stamp, boolean updatePT)
          Update the current stamp value
 boolean verifyLastStampIndex()
          Verify if the last (highest) stamp is correctly indexed.
 boolean verifyStampLineMap()
          Verify if the stamps are correctly indexed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REVISION

public static final String REVISION
See Also:
Constant Field Values

DEFAULT_HANDLER_FLAG

public static final boolean DEFAULT_HANDLER_FLAG
See Also:
Constant Field Values

storeAccessLock

public Object storeAccessLock
Constructor Detail

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

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

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
Method Detail

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

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
Returns:
the number of operations outputted
Throws:
LogException

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
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
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

replaceSuffix

public void replaceSuffix(TreeSet<StorableLogEntry> newSuffix,
                          LogEntry startLogEntry,
                          boolean includeStart)
                   throws IOException
Throws:
IOException
Since:
jcms-4.1
See Also:
LogManager.replaceSuffix(java.util.TreeSet,com.jalios.jstore.LogEntry,boolean,boolean)

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
Since:
jcms-4.1

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:
StampManager.getUrid()

setUrid

public void setUrid(String urid)
Set the current urid value

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()

getProgressTable

public StampTable getProgressTable()
Return the progressTable

Returns:
the map of greatest stamp
See Also:
StampManager.getProgressTable()

getProgressStamp

public Stamp getProgressStamp()
Return the greatest stamp of this urid

Returns:
a Stamp
See Also:
StampManager.getProgressStamp(String)

getProgressStamp

public Stamp getProgressStamp(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()
          throws LogException
Load and process the log

Throws:
LogException

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
Since:
jcms-4.0.2

processLogEntry

public void processLogEntry(LogEntry logEntry)

processInnerLogEntry

public void processInnerLogEntry(InnerLogEntry logEntry)

processStorableLogEntry

public void processStorableLogEntry(StorableLogEntry storableLog)

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

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 -
overrideId -
Throws:
IOException
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

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

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
NoUpdateException

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:
NoUpdateException - on error, for example when given objects are same instance
IOException

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

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

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
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
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
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

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

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

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(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:
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 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.



Copyright © 2001-2010 Jalios SA. All Rights Reserved.