Package com.jalios.jstore
Class Store
java.lang.Object
com.jalios.jstore.Store
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanFields 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, LOG_DIR_LOG_PREFIX, LOG_DIR_LOG_WORK, MAP_ASSIGN, MAP_CHARS_TO_ESCAPE, MAP_CLASS_SEPARATOR, MAP_FLAG, NAMESPACE, SH_SUFFIX, STORING_STATE, UPDATE_OP -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new Store which does not support precompiled store handlers nor in-memory parsing.Create a new Store which does not support precompiled store handlers.Create a new Store -
Method Summary
Modifier and TypeMethodDescriptionvoidaddClassTag(String tag, Class<?> clazz) Binds a tag name with a Storable class.voidaddExtraDeleteAttribute(String attName) Adds an attribute which will be stored when a storable is deleted.voidaddStoreListener(StoreListener listener, boolean repeat) voidaddStoreListener(StoreListener listener, Class<?> clazz, boolean repeat) voidappendAndProcessSuffix(List<? extends LogEntry> logEntryList) Appends the given LogEntries in the store.xml file and process each of them.voidappendMilestone(String text) Appends a milestone in the store.voidappendMilestone(Map<String, String> map) Appends a milestone in the store.voidappendSync(Date date) Appends a sync tag in the store.booleanbackupStore(File backupFile) Backup the store.voidclose()Close all Store resources when ending.voidCreate a storable, set storable id to stamp value.voidCreate a storable, if overrideId is false and storable have an id then do not override id.voidDelete a storable (even if references remain on it).voidDelete a storable.intgenerateDelta(OutputStream out, Stamp startStamp, boolean includeStart) Ouput in a given stream all the log operations having a stamp greater that the given one.voidgenerateLogFromMemory(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 returnedlongReturns the line number in the store file of the creation.getDeletedSet(Class<?> clazz) Get the latest version of the deleted Storable for a given class.Returns the list of attributes stored when a storable is deleted.Return the load reportReturns the LogCleaner.Return the name of the log directory.longlongReturn the name of the log file.longReturns the list of milestones.longReturn the greatest stamp of this uridgetProgressStamp(String urid) Return the greatest stamp of the given uridReturn the progressTableintgetSize()Return the size of the store.getStamp()Return a new stamp.longgetStampLineNumber(Stamp stamp) Returns the line number in the store file of the given stamp.longgetStampLineNumberInLogWork(Stamp stamp) Returns the line number in the log work file for the given stamp.intgetState()Return the current state of the store (see StoreConstants).getStorable(String id) Return the storable given its idMap<Class<?>, Set<StoreListener>> getStoreClassListeners(boolean repeat) getStoreListeners(boolean repeat) Return the SyncManagergetTagFromClass(Class<?> clazz) Returns the tag name binded with a specified classgetUrid()getVersionList(Storable storable) Get all the version of a given StorablegetVersionList(String id) Get all the version of a given Storable IDbooleanbooleanisReferrenced(Storable storable) booleanisRegistered(Storable storable) booleanisRegistered(String id) iterator()Return an iterator on the storables registered in the swizzlervoidload()Load and process the logvoidload(boolean processStorable, boolean processInner) Load and process the loglongmoveOperations(Stamp stamp, long expectedLineCount) Move the operations of store-work.xml to the most recent store-prefix-n.xml.voidparseLog(LogManagerHandler handler) Parse the store with the given handlerbooleanparseLog(LogManagerHandler handler, long startLine) Parse the store with the given handler from the given line numbervoidparseLog(LogManagerHandler handler, long startLine, boolean includeLogWork) Parse the store with the given handler from the given stampvoidparseLog(LogManagerHandler handler, Stamp stamp) Parse the store with the given handler from the given stampvoidPrints a cleaned version of the log.voidprocessInnerLogEntry(InnerLogEntry logEntry) voidprocessLogEntry(LogEntry logEntry) voidvoidvoidvoidremoveStoreListener(StoreListener listener) voidremoveStoreListener(StoreListener listener, Class<?> clazz) voidreplaceSuffix(TreeSet<StorableLogEntry> newSuffix, LogEntry startLogEntry, boolean includeStart) voidsetClassLoader(ClassLoader classLoader) Set the classLoadervoidsetLogDirectoryFileMaxSize(long logDirFileMaxSize) voidsetReplaceSuffixLimit(int replaceSuffixLimit) A store suffix replacement starting before the limit will be rejected.voidSet the current urid valuebooleanstampExists(Stamp stamp) voidUpdate a storable.voidUpdate a storable.voidUpdate a storable.voidUpdate a storable.voidupdateStamp(Stamp stamp) Update the current stamp value (and the progress table)voidupdateStamp(Stamp stamp, boolean updatePT) Update the current stamp valuebooleanVerify if the last (highest) stamp is correctly indexed.booleanVerify if the stamps are correctly indexed.
-
Field Details
-
DEFAULT_HANDLER_FLAG
public static final boolean DEFAULT_HANDLER_FLAG- See Also:
-
storeAccessLock
-
-
Constructor Details
-
Store
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
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:
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 logareHandlersEnabled- specify if the precompiled store handlers are supported.urid- the URIDuseNIO- specify if the NIO must be used (faster store access)- Throws:
IOException- if an error occurs
-
-
Method Details
-
addExtraDeleteAttribute
Adds an attribute which will be stored when a storable is deleted.- Parameters:
attName- the attribute name- Since:
- jcms-5.5.0
-
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
Set the classLoader- Parameters:
classLoader- the classLoader to use
-
addClassTag
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
Returns the tag name binded with a specified class- Parameters:
clazz- the class- Returns:
- the tag name for clazz
-
getClassFromTag
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
Return the storable given its id- Parameters:
id- the storable id- Returns:
- the storable bound with this id
-
isReferrenced
- Parameters:
storable- the storable to check- Returns:
- true if there is exist at least one storable which references the given storable
-
isRegistered
- Parameters:
storable- the storable to check- Returns:
- true if the storable is still registered
- Since:
- jcms-5.0.0
-
isRegistered
- Parameters:
id- the storable id- Returns:
- true if the storable is still registered
- Since:
- jcms-5.0.0
-
getVersionList
Get all the version of a given Storable- Parameters:
storable- the storable- Returns:
- a list of Storable
-
getVersionList
Get all the version of a given Storable ID- Parameters:
id- the ID of storable- Returns:
- a list of Storable
-
getDeletedSet
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 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
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
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 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 storestartLine- the first line to start the parsingincludeLogWork- if true include the logWork- Throws:
LogException- if an error occurs- Since:
- jcms-11.0.1
-
parseLog
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(TreeSet<StorableLogEntry> newSuffix, LogEntry startLogEntry, boolean includeStart) throws IOException - Parameters:
newSuffix- The new suffixstartLogEntry- the start logEntryincludeStart- true if the startLogEntry must be included- Throws:
IOException- if an error occurs- Since:
- jcms-4.1
- See Also:
-
appendAndProcessSuffix
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
- Parameters:
stamp- the stamp- Returns:
- true if the given stamp exists
- Since:
- jcms-10.0.8
-
moveOperations
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
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
- Returns:
- the current urid value
- See Also:
-
setUrid
Set the current urid value- Parameters:
urid- the URID- See Also:
-
updateStamp
Update the current stamp value (and the progress table)- Parameters:
stamp- the stamp to be added- Since:
- jcms-4.0
- See Also:
-
updateStamp
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:
-
getStamp
Return a new stamp. Ensures their strict monotonicity.- Returns:
- a new stamp
- Since:
- jcms-4.0.2
- See Also:
-
getProgressTable
Return the progressTable- Returns:
- the map of greatest stamp
- See Also:
-
getProgressStamp
Return the greatest stamp of this urid- Returns:
- a Stamp
- See Also:
-
getProgressStamp
Return the greatest stamp of the given urid- Parameters:
urid- the urid- Returns:
- a Stamp
- See Also:
-
getSyncManager
Return the SyncManager- Returns:
- the SyncManager
- Since:
- jcms-4.0.2
-
load
Load and process the log- Throws:
LogException- if an error occurs
-
load
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
-
processInnerLogEntry
-
processStorableLogEntry
-
create
Create a storable, set storable id to stamp value.- Parameters:
storable- the storable to create.- Throws:
IOException- if an error occurs
-
create
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:
IOException- if an error occurs- Since:
- jcms-4.0
-
update
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:
IOException- if an error occurs
-
update
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:
IOException- if an error occurs
-
update
Update a storable. The stored update only concerns fields that are differents (i.e. not the same object) betweenstorableandupdated.- Parameters:
id- the id of the storable to updateupdated- the updated storable- Throws:
IOException- if an error occursNoUpdateException- if an error occurs
-
update
Update a storable. The stored update only concerns fields that are differents (i.e. not the same object) betweenstorableandupdated.- Parameters:
storable- the storable to updateupdated- the updated storable- Throws:
IOException- if an error occursNoUpdateException- on error, for example when given objects are same instance
-
delete
Delete a storable (even if references remain on it).- Parameters:
storable- the storable to delete- Throws:
IOException- if an error occurs
-
delete
Delete a storable.- Parameters:
storable- the storable to deleteforce- if true the referenced storable attributes are deleted- Throws:
IOException- if an error occurs
-
getMilestoneList
Returns the list of milestones.- Returns:
- the list of milestones.
- Since:
- jcms-5.5.0
-
appendMilestone
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
Appends a milestone in the store.- Parameters:
map- the map of attributes.- Throws:
IOException- if an error occurs- Since:
- jcms-5.5.0
-
appendSync
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
Cleans the log. The current log file is remplaced by a new one which contains the result ofprintCleanedLogmethod. 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:
IOException- if an error occurs
-
printMemoryToLog
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
Returns the LogCleaner.- Returns:
- the LogCleaner.
- Since:
- jcms-5.5.0
-
getLogFilename
Return the name of the log file.- Returns:
- the name of the log 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
- Returns:
- the list of files in the log directory.
- Since:
- jcms-10.0.8
-
getLogFile
- Returns:
- the log file.
- Since:
- jcms-10.0.8
-
getLogWorkFile
-
getLatestLogPrefixFile
-
getPrefixLineCount
public long getPrefixLineCount()- Returns:
- the number of lines in all store prefix files.
- Since:
- jcms-10.0.8
-
getLogDirectoryFileLineCount
- 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
- Throws:
LogException
-
refreshLogFile
- Throws:
LogException
-
setLogDirectoryFileMaxSize
public void setLogDirectoryFileMaxSize(long logDirFileMaxSize) -
getLogDirectoryFileMaxSize
public long getLogDirectoryFileMaxSize() -
getLoadReport
Return the load report- Returns:
- a LoadReport instance
-
getStampLineNumber
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
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
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
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
-
getStoreClassListeners
-
addStoreListener
-
addStoreListener
-
removeStoreListener
-
removeStoreListener
-
close
public void close()Close all Store resources when ending.
-