Class VersionedObjectStore
- java.lang.Object
- 
- hudson.plugins.project_inheritance.util.VersionedObjectStore
 
- 
- All Implemented Interfaces:
- Serializable
 
 public class VersionedObjectStore extends Object implements Serializable This class allows you to version-control almost arbitrary objects. TODO: This class is in heavy need of a read/write lock TODO: Improve the JavaDoc of this class.- Author:
- mhschroe
- See Also:
- Serialized Form
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classVersionedObjectStore.Version
 - 
Constructor SummaryConstructors Constructor Description VersionedObjectStore()
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanareIdentical(VersionedObjectStore.Version v1, VersionedObjectStore.Version v2)VersionedObjectStore.VersioncreateNextVersion()This method creates the next version and copies all key/value object entries from the previous one.VersionedObjectStore.VersioncreateNextVersionAsEmpty()Creates the next version with an empty key/value object mapping.VersionedObjectStore.VersioncreateNextVersionWithMapping(Map<String,Object> map)Collection<HashMap<String,Object>>getAllValueMaps()SortedSet<VersionedObjectStore.Version>getAllVersions()Returns a new set of all versions, sorted by their ID in ascending order.LinkedList<VersionedObjectStore.Version>getAllVersionsSince(Long sinceVersionId)gets all the more recent version ids since the sinceVersionIdVersionedObjectStore.VersiongetLatestStable()VersionedObjectStore.VersiongetLatestVersion()This retrieves the actual last versioned object.VersionedObjectStore.VersiongetNearestTo(Long timestamp)ObjectgetObject(VersionedObjectStore.Version version, String key)ObjectgetObject(Long id, String key)VersionsNotificationgetUserNotificationFor(Long version)This method generates a notification to the user, depending on what type of version currently being edited: user is editing an unstable version (Warning) user is editing the last stable version which is not the last version (Warning) user is editing the last stable version which is the last version (Info) user is editing some stable version which is not the latest stable version (Warning)Map<String,Object>getValueMapFor(Long id)This returns an immutable map that wraps around the key/value object map associated with the given version.VersionedObjectStore.VersiongetVersion(Long id)static VersionedObjectStoreload(File file)Loads aVersionedObjectStorefrom the given file.voidsave(File file)Calling this function causes the store to be saved to disk.booleansetObjectFor(VersionedObjectStore.Version v, String key, Object value)intsize()StringtoString()StringtoXML()voidundoVersion(VersionedObjectStore.Version v)This function removes the given version from the internal storage, if it is the last version that is present.
 
- 
- 
- 
Method Detail- 
toXMLpublic String toXML() 
 - 
sizepublic int size() 
 - 
savepublic void save(File file) throws IOException Calling this function causes the store to be saved to disk. Not making the save automatic allows you to make bulk-changes and only dump them to disk once finished. Do note that while the function itself is synchronized, at the moment nothing prevents others to change the underlying data fields during save. TODO: Fix this, so that saves are truly atomic. Do note that this function fails silently in case the output file is not writable. It will log an error, but do nothing beyond that- Parameters:
- file- the file to save the data to. The data is dumped as GZIP-compressed XML.
- Throws:
- IOException- in case the save file can't be read.
 
 - 
loadpublic static VersionedObjectStore load(File file) throws IllegalArgumentException, IOException, com.thoughtworks.xstream.XStreamException Loads aVersionedObjectStorefrom the given file.- Parameters:
- file- the file to load data from. Must be XML -- either raw or GZIP compressed.
- Returns:
- a newly created VersionedObjectStore.
- Throws:
- IOException- in case the file can't be read.
- IllegalArgumentException- in case the file contains invalid data.
- com.thoughtworks.xstream.XStreamException- in case of XML serialisation error
 
 - 
areIdenticalpublic boolean areIdentical(VersionedObjectStore.Version v1, VersionedObjectStore.Version v2) 
 - 
getLatestVersionpublic VersionedObjectStore.Version getLatestVersion() This retrieves the actual last versioned object.- Returns:
- the latest version, or null if no version exists
 
 - 
getVersionpublic VersionedObjectStore.Version getVersion(Long id) 
 - 
getLatestStablepublic VersionedObjectStore.Version getLatestStable() 
 - 
getAllVersionsSincepublic LinkedList<VersionedObjectStore.Version> getAllVersionsSince(Long sinceVersionId) gets all the more recent version ids since the sinceVersionId- Parameters:
- sinceVersionId- timestamp in milliseconds since the epoch
- Returns:
- all versions since the given timestamp
 
 - 
getNearestTopublic VersionedObjectStore.Version getNearestTo(Long timestamp) 
 - 
getAllVersionspublic SortedSet<VersionedObjectStore.Version> getAllVersions() Returns a new set of all versions, sorted by their ID in ascending order.- Returns:
- a sorted set of versions in ascending order.
 
 - 
getAllValueMapspublic Collection<HashMap<String,Object>> getAllValueMaps() 
 - 
createNextVersionpublic VersionedObjectStore.Version createNextVersion() This method creates the next version and copies all key/value object entries from the previous one.- Returns:
- a blank next version.
 
 - 
undoVersionpublic void undoVersion(VersionedObjectStore.Version v) This function removes the given version from the internal storage, if it is the last version that is present.You should not expose this function to the outside. Ever! - Parameters:
- v- the version to commit
 
 - 
createNextVersionAsEmptypublic VersionedObjectStore.Version createNextVersionAsEmpty() Creates the next version with an empty key/value object mapping.- Returns:
- a blank, next version
 
 - 
createNextVersionWithMappingpublic VersionedObjectStore.Version createNextVersionWithMapping(Map<String,Object> map) 
 - 
getObjectpublic Object getObject(VersionedObjectStore.Version version, String key) 
 - 
getValueMapForpublic Map<String,Object> getValueMapFor(Long id) This returns an immutable map that wraps around the key/value object map associated with the given version.Use this method in favour of getObject(Long, String)to avoid the O(log(n)) cost of retrieving the given version if you access more than one stored object.- Parameters:
- id- the numerical ID of the version to retrieve
- Returns:
- an immutable map of key/value object pairs
 
 - 
setObjectForpublic boolean setObjectFor(VersionedObjectStore.Version v, String key, Object value) 
 - 
getUserNotificationForpublic VersionsNotification getUserNotificationFor(Long version) This method generates a notification to the user, depending on what type of version currently being edited:- user is editing an unstable version (Warning)
- user is editing the last stable version which is not the last version (Warning)
- user is editing the last stable version which is the last version (Info)
- user is editing some stable version which is not the latest stable version (Warning)
 - Parameters:
- version- the specific version for which to get the notification
- Returns:
- a notification about the suitability of the given version
 
 
- 
 
-