Package com.jalios.jstore
Class Store
- java.lang.Object
-
- com.jalios.jstore.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 Summary
Fields Modifier and Type Field Description static boolean
DEFAULT_HANDLER_FLAG
static java.lang.String
REVISION
java.lang.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
Constructors Constructor Description Store(java.lang.String logFilename)
Create a new Store which does not support precompiled store handlers nor in-memory parsing.Store(java.lang.String logFilename, boolean areHandlersEnabled)
Create a new Store which does not support precompiled store handlers.Store(java.lang.String logFilename, boolean areHandlersEnabled, java.lang.String urid, boolean useNIO)
Create a new Store
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addClassTag(java.lang.String tag, java.lang.Class<?> clazz)
Binds a tag name with a Storable class.void
addExtraDeleteAttribute(java.lang.String attName)
Adds an attribute which will be stored when a storable is deleted.void
addStoreListener(StoreListener listener, boolean repeat)
void
addStoreListener(StoreListener listener, java.lang.Class<?> clazz, boolean repeat)
void
appendAndProcessSuffix(java.util.List<? extends LogEntry> logEntryList)
Appends the given LogEntries in the store.xml file and process each of them.void
appendMilestone(java.lang.String text)
Appends a milestone in the store.void
appendMilestone(java.util.Map<java.lang.String,java.lang.String> map)
Appends a milestone in the store.void
appendSync(java.util.Date date)
Appends a sync tag in the store.boolean
backupStore(java.io.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(java.io.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(java.lang.String backupFilename)
Cleans the log.java.lang.Class<?>
getClassFromTag(java.lang.String tag)
Returns the class binded with a specified tag name If the class was not registered the class associated
to the name is returnedint
getCreationLineNumber(java.lang.String id)
Returns the line number in the store file of the creation.java.util.TreeSet<? extends Storable>
getDeletedSet(java.lang.Class<?> clazz)
Get the latest version of the deleted Storable for a given class.java.util.Set<java.lang.String>
getExtraDeleteAttributeSet()
Returns the list of attributes stored when a storable is deleted.LoadReport
getLoadReport()
Return the load reportLogCleaner
getLogCleaner()
Returns the LogCleaner.java.lang.String
getLogFilename()
Return the name of the log file.java.util.List<InnerLogEntry>
getMilestoneList()
Returns the list of milestones.Stamp
getProgressStamp()
Return the greatest stamp of this uridStamp
getProgressStamp(java.lang.String urid)
Return the greatest stamp of the given uridStampTable
getProgressTable()
Return the progressTableint
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(java.lang.String id)
Return the storable given its idjava.util.Map<java.lang.Class<?>,java.util.Set<StoreListener>>
getStoreClassListeners(boolean repeat)
java.util.Set<StoreListener>
getStoreListeners(boolean repeat)
SyncManager
getSyncManager()
Return the SyncManagerjava.lang.String
getTagFromClass(java.lang.Class<?> clazz)
Returns the tag name binded with a specified classjava.lang.String
getUrid()
java.util.List<? extends Storable>
getVersionList(Storable storable)
Get all the version of a given Storablejava.util.List<? extends Storable>
getVersionList(java.lang.String id)
Get all the version of a given Storable IDboolean
isReferrenced(Storable storable)
boolean
isRegistered(Storable storable)
boolean
isRegistered(java.lang.String id)
java.util.Iterator<Storable>
iterator()
Return an iterator on the storables registered in the swizzlervoid
load()
Load and process the logvoid
load(boolean processStorable, boolean processInner)
Load and process the logvoid
parseLog(LogManagerHandler handler)
Parse the store with the given handlerboolean
parseLog(LogManagerHandler handler, int startLine)
Parse the store with the given handler from the given line numbervoid
parseLog(LogManagerHandler handler, Stamp stamp)
Parse the store with the given handler from the given stampvoid
printMemoryToLog(java.io.OutputStream out)
Prints a cleaned version of the log.void
processInnerLogEntry(InnerLogEntry logEntry)
void
processLogEntry(LogEntry logEntry)
void
processStorableLogEntry(StorableLogEntry sle)
void
removeStoreListener(StoreListener listener)
void
removeStoreListener(StoreListener listener, java.lang.Class<?> clazz)
void
replaceSuffix(java.util.TreeSet<StorableLogEntry> newSuffix, LogEntry startLogEntry, boolean includeStart)
void
setClassLoader(java.lang.ClassLoader classLoader)
Set the classLoadervoid
setReplaceSuffixLimit(int replaceSuffixLimit)
A store suffix replacement starting before the limit will be rejected.void
setUrid(java.lang.String urid)
Set the current urid valuevoid
update(Storable storable, Storable updated)
Update a storable.void
update(Storable storable, java.util.Map<java.lang.String,java.lang.String> attributes)
Update a storable.void
update(java.lang.String id, Storable updated)
Update a storable.void
update(java.lang.String id, java.util.Map<java.lang.String,java.lang.String> attributes)
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 valueboolean
verifyLastStampIndex()
Verify if the last (highest) stamp is correctly indexed.boolean
verifyStampLineMap()
Verify if the stamps are correctly indexed.
-
-
-
Field Detail
-
REVISION
public static final java.lang.String REVISION
- See Also:
- Constant Field Values
-
DEFAULT_HANDLER_FLAG
public static final boolean DEFAULT_HANDLER_FLAG
- See Also:
- Constant Field Values
-
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 logareHandlersEnabled
- 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 logareHandlersEnabled
- specify if the precompiled store handlers are supported.urid
- the URIDuseNIO
- 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 tagclazz
- 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 operationsstartStamp
- the stamp to start the copyincludeStart
- 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 storestamp
- 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 storestartLine
- 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(java.util.TreeSet<StorableLogEntry> newSuffix, LogEntry startLogEntry, boolean includeStart) throws java.io.IOException
- Parameters:
newSuffix
- The new suffixstartLogEntry
- the start logEntryincludeStart
- true if the startLogEntry must be included- Throws:
java.io.IOException
- if an error occurs- Since:
- jcms-4.1
- See Also:
LogManager.replaceSuffix(java.util.TreeSet,com.jalios.jstore.LogEntry,boolean,boolean)
-
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 addedupdatePT
- 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(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() 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 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 storableoverrideId
- 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 updateattributes
- 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 updateattributes
- 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) betweenstorable
andupdated
.- Parameters:
id
- the id of the storable to updateupdated
- the updated storable- Throws:
java.io.IOException
- if an error occursNoUpdateException
- 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) betweenstorable
andupdated
.- Parameters:
storable
- the storable to updateupdated
- the updated storable- Throws:
java.io.IOException
- if an error occursNoUpdateException
- 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 deleteforce
- 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 ofprintCleanedLog
method. If a backup filename is provided (i.e. notnull
), 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.
-
-