org.garret.perst
Class VersionHistory

java.lang.Object
  extended byorg.garret.perst.Persistent
      extended byorg.garret.perst.PersistentResource
          extended byorg.garret.perst.VersionHistory
All Implemented Interfaces:
java.io.Externalizable, IPersistent, IResource, java.io.Serializable

public class VersionHistory
extends PersistentResource

Collection of version of versioned object. Versioned object should be access through version history object. Instead of storing direct reference to Verson in some component of some other persistent object, it is necessary to store reference to it's VersionHistory.

See Also:
Serialized Form

Constructor Summary
VersionHistory(Version root)
          Create new version history
 
Method Summary
 Version checkout()
          Checkout current version: create successor of the current version.
 Version[] getAllVersions()
          Get all versions in version history
 Version getCurrent()
          Get current version in version history.
 Version getEarliestAfter(java.util.Date timestamp)
          Get earliest version adter specified date
 Version getLatestBefore(java.util.Date timestamp)
          Get latest version before specified date
 Version getRoot()
          Get root version
 Version getVersionById(java.lang.String id)
          Get version with specified ID.
 Version getVersionByLabel(java.lang.String label)
          Get version with specified label.
 java.util.Iterator iterator()
          Get iterator through all version in version history Iteration is started from the root version and performed in direction of increaing version timestamp This iterator supports remove() method.
 void setCurrent(Version version)
          Set new current version in version history
 
Methods inherited from class org.garret.perst.PersistentResource
exclusiveLock, exclusiveLock, reset, sharedLock, sharedLock, unlock
 
Methods inherited from class org.garret.perst.Persistent
assignOid, deallocate, equals, getOid, getStorage, hashCode, invalidate, isDeleted, isModified, isPersistent, isRaw, load, loadAndModify, makePersistent, modify, onLoad, onStore, readExternal, recursiveLoading, store, writeExternal
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VersionHistory

public VersionHistory(Version root)
Create new version history

Parameters:
root - root version
Method Detail

checkout

public Version checkout()
Checkout current version: create successor of the current version. This version has to be checked-in in order to be placed in version history

Returns:
checked-out version

getAllVersions

public Version[] getAllVersions()
Get all versions in version history

Returns:
array of versions sorted by date

getCurrent

public Version getCurrent()
Get current version in version history. Current version can be explicitely set by setVersion or result of last checkOut is used as current version


getEarliestAfter

public Version getEarliestAfter(java.util.Date timestamp)
Get earliest version adter specified date

Parameters:
timestamp - deadline, if null then root version will be returned
Returns:
version with the smallest timestamp greater than specified timestamp

getLatestBefore

public Version getLatestBefore(java.util.Date timestamp)
Get latest version before specified date

Parameters:
timestamp - deadline, if null then the latest version in version history will be returned
Returns:
version with the largest timestamp less than specified timestamp

getRoot

public Version getRoot()
Get root version

Returns:
root version in this version history

getVersionById

public Version getVersionById(java.lang.String id)
Get version with specified ID.

Parameters:
id - version ID
Returns:
version with specified ID

getVersionByLabel

public Version getVersionByLabel(java.lang.String label)
Get version with specified label. If there are more than one version marked with this label, then the latest one will be returned

Parameters:
label - version label
Returns:
latest version with specified label

iterator

public java.util.Iterator iterator()
Get iterator through all version in version history Iteration is started from the root version and performed in direction of increaing version timestamp This iterator supports remove() method.

Returns:
version iterator

setCurrent

public void setCurrent(Version version)
Set new current version in version history

Parameters:
version - new current version in version history (it must belong to version history)