org.garret.perst
Class VersionHistory<V extends Version>

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

public class VersionHistory<V extends Version>
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(V root)
          Create new version history
 
Method Summary
 V checkout()
          Checkout current version: create successor of the current version.
 Version[] getAllVersions()
          Get all versions in version history
 V getCurrent()
          Get current version in version history.
 V getEarliestAfter(java.util.Date timestamp)
          Get earliest version adter specified date
 V getLatestBefore(java.util.Date timestamp)
          Get latest version before specified date
 V getRoot()
          Get root version
 V getVersionById(java.lang.String id)
          Get version with specified ID.
 V getVersionByLabel(java.lang.String label)
          Get version with specified label.
 java.util.Iterator<V> 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(V 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(V root)
Create new version history

Parameters:
root - root version
Method Detail

checkout

public V 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 V 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 V 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 V 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 V getRoot()
Get root version

Returns:
root version in this version history

getVersionById

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

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

getVersionByLabel

public V 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<V> 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(V version)
Set new current version in version history

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