org.ov4j
Class Controler<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>

java.lang.Object
  extended by org.ov4j.Controler<T,C>

public class Controler<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
extends java.lang.Object

Main access to the versioning system.

Author:
smolloy

Constructor Summary
Controler(IContainer<T,C> db)
          Instantiate a Controler using the specified container to store its data.
 
Method Summary
 boolean addNCommit(C id, Version<T> ver)
          Directly add a version.
 boolean batchCommit(C[] ids, Version<T>[] newVersions, java.lang.Class<? extends ComparisonResult<T>> compResultClass, boolean addNew)
          Commit changes to the given objects using the specified class to determine if commit is needed.
 boolean batchDelete(C[] ids)
          Removes all versions of the given ids.
 boolean batchDiscard(C[] ids)
          Remove all version and do not keep IDs in history.
 boolean batchImport(C[] ids, Version<T>[] vers, boolean abortOnDuplicate)
          Add all versions, will return a BiteSet containing information on which could be added.
 boolean batchMerge(C[] ids)
          Merges all versions of the given ids.
 void clear()
          Clear all data in the underlying container.
 void close()
          Close this controler and its underlying container.
 boolean commit(C id, Version<T> newVersion)
          Commit changes to the given object.
 boolean commit(C id, Version<T> newVersion, java.lang.Class<? extends ComparisonResult<? super T>> compResultClass)
          Commit changes to the given object.
 boolean commit(C id, Version<T> newVersion, java.lang.Class<? extends ComparisonResult<? super T>> compResultClass, int rollover)
          Commit changes to the given object using the specified class to determine if commit is needed.
 boolean commit(C id, Version<T> newVersion, int rollover)
          Commit changes to the given object.
 ComparisonResult<T> compare(Version<T> newVersion, Version<T> oldVersion, boolean fast)
          Compare 2 versions after determining which class to use.
 ComparisonResult<T> compare(Version<T> newVersion, Version<T> oldVersion, java.lang.Class<? extends ComparisonResult<? super T>> compResultClass, boolean fast)
          Compare 2 versions using the specified class.
 boolean delete(C id)
          Removes all versions of the given id.
 C[] deletedIds()
          Retrieve list of IDs that have been deleted.
 C[] deletedIdsSince(long timestamp)
          Retrieve a list of IDs that have been deleted since the given timestamp.
 ComparisonResult<T> diff(C id, Version<T> newVersion)
          Will perform a diff, trying to determine the class of the comparison result by appending ComparisonResult to the versionedObject classname.
 ComparisonResult<T> diff(C id, Version<T> newVersion, java.lang.Class<? extends ComparisonResult<? super T>> compResultClass)
          Compares the new version to the latest version of object with the given id.
 boolean discard(C id)
          Remove all version and do not keep ID in history.
 void discardChanges()
          Discard all changes made since the last save.
 Version<T> fetch(C id, int versionNum)
          Fetch the given version of object with the given id.
 Version<T>[] fetch(C id, int[] versionNums)
          Fetch the given versions of object with the given id.
 java.lang.Class<? extends ComparisonResult<? super T>> findComparisonResultClass(Version<T> ver)
          Find the Class to use for comparing this version, will replace "data" by "comp" in the package name and add "ComparisonResult" to the class of the versions's versioned object.
 int getVersionRollover()
          Retrieve the number of versions kept for historical purposes.
 boolean inUse(C id)
          Determine if the given id is already in use.
 boolean isClosed()
          Determine if the underlying container has already been closed.
 Version<T> latest(C id)
          Fetch the latest version of the object with given id.
 Version<T> latest(C id, int tstamp)
          Fetch the latest version of the object with given id before the given timestamp.
 Version<T>[] latests(C[] ids)
          Fetch the latest versions of every id specified.
 Version<T>[] latests(C[] ids, int tstamp)
          Fetch the latest versions of every id specified before the given timestamp.
 C[] listModifiedSince(long timestamp)
          List the latest versions modified since the given timestamp.
 Version<T>[] modifiedSince(long timestamp)
          Fetch the latest versions modified since the given timestamp.
 void saveChanges()
          Save all changes in the container.
 void setVersionRollover(int versionRollover)
          Set the number of versions kept for historical purposes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Controler

public Controler(IContainer<T,C> db)
Instantiate a Controler using the specified container to store its data.

Parameters:
db - Container used for storing data.
Method Detail

addNCommit

public boolean addNCommit(C id,
                          Version<T> ver)
                   throws java.io.IOException
Directly add a version.

Type Parameters:
T - Type of the object stored in version, must extend VersionableObject.
Parameters:
id - ID to associate with the version.
ver - Version to be added.
Returns:
True if the version was successfully added, false otherwise.
Throws:
java.io.IOException

batchCommit

public boolean batchCommit(C[] ids,
                           Version<T>[] newVersions,
                           java.lang.Class<? extends ComparisonResult<T>> compResultClass,
                           boolean addNew)
                    throws java.lang.InstantiationException,
                           java.lang.IllegalAccessException,
                           java.io.IOException
Commit changes to the given objects using the specified class to determine if commit is needed. This method will add new ids if the addNew parameter is set to true, otherwise they will be ignored.

Parameters:
ids - Array of IDs associated with the versions to commit, must be in the same order.
newVersions - Array of versions to be committed, must be in the same order.
compResultClass - Class to use for comparing objects in the versions.
addNew - Whether or not to add versions associated with IDs not found in the system.
Returns:
True if batch commit was successful.
Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException
java.io.IOException

batchDelete

public boolean batchDelete(C[] ids)
                    throws java.io.IOException
Removes all versions of the given ids.

Parameters:
ids - IDs to be deleted.
Returns:
True if IDs were successfully deleted.
Throws:
java.io.IOException

batchDiscard

public boolean batchDiscard(C[] ids)
                     throws java.io.IOException
Remove all version and do not keep IDs in history.

Parameters:
ids - IDs to be deleted.
Returns:
True if IDs were successfully discarded.
Throws:
java.io.IOException

batchImport

public boolean batchImport(C[] ids,
                           Version<T>[] vers,
                           boolean abortOnDuplicate)
                    throws java.io.IOException
Add all versions, will return a BiteSet containing information on which could be added. If abortOnDuplicate is set to true, nothing will be committed unless none of the ids passed were already in use.

Type Parameters:
T - Type of the object stored in versions, must extend VersionableObject.
Parameters:
ids - Array of IDs to associate with the versions, must be in the same order.
vers - Array of versions to add, must be in the same order.
abortOnDuplicate - Whether or not to abort import if one of the IDs specified is already in use.
Returns:
True if adding was successful.
Throws:
java.io.IOException

batchMerge

public boolean batchMerge(C[] ids)
                   throws java.io.IOException
Merges all versions of the given ids.

Parameters:
ids - IDs to be deleted.
Returns:
True if IDs were successfully deleted.
Throws:
java.io.IOException

clear

public void clear()
Clear all data in the underlying container.


close

public void close()
Close this controler and its underlying container.


commit

public boolean commit(C id,
                      Version<T> newVersion)
               throws java.lang.InstantiationException,
                      java.lang.IllegalAccessException,
                      java.io.IOException
Commit changes to the given object.

Parameters:
id - ID associated with the version to commit.
newVersion - New version to be committed.
Returns:
True if version was committed successfully.
Throws:
java.lang.IllegalAccessException
java.lang.InstantiationException
java.io.IOException

commit

public boolean commit(C id,
                      Version<T> newVersion,
                      java.lang.Class<? extends ComparisonResult<? super T>> compResultClass)
               throws java.lang.InstantiationException,
                      java.lang.IllegalAccessException,
                      java.io.IOException
Commit changes to the given object.

Parameters:
id - ID associated with the version to commit.
newVersion - New version to be committed.
compResultClass - Class to use to compare objects in the version.
Returns:
True if version was committed successfully.
Throws:
java.lang.IllegalAccessException
java.lang.InstantiationException
java.io.IOException

commit

public boolean commit(C id,
                      Version<T> newVersion,
                      java.lang.Class<? extends ComparisonResult<? super T>> compResultClass,
                      int rollover)
               throws java.lang.InstantiationException,
                      java.lang.IllegalAccessException,
                      java.io.IOException
Commit changes to the given object using the specified class to determine if commit is needed.

Parameters:
id - ID associated with the version to commit.
newVersion - New version to be committed.
compResultClass - Class to use to compare objects in the version.
rollover - Version rollover to use.
Returns:
True if version was committed successfully.
Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException
java.io.IOException

commit

public boolean commit(C id,
                      Version<T> newVersion,
                      int rollover)
               throws java.lang.InstantiationException,
                      java.lang.IllegalAccessException,
                      java.io.IOException
Commit changes to the given object.

Parameters:
id - ID associated with the version to commit.
newVersion - New version to be committed.
rollover - Version rollover to use.
Returns:
True if version was committed successfully.
Throws:
java.lang.IllegalAccessException
java.lang.InstantiationException
java.io.IOException

compare

public ComparisonResult<T> compare(Version<T> newVersion,
                                   Version<T> oldVersion,
                                   boolean fast)
                                                                                                               throws java.lang.InstantiationException,
                                                                                                                      java.lang.IllegalAccessException
Compare 2 versions after determining which class to use.

Parameters:
newVersion - New version to be compared.
oldVersion - Old version to compare to.
fast - Whether or not to run in fast mode, only determining if versions are the same or not.
Returns:
A ComparisonResult holding comparison information about the 2 versions.
Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException

compare

public ComparisonResult<T> compare(Version<T> newVersion,
                                   Version<T> oldVersion,
                                   java.lang.Class<? extends ComparisonResult<? super T>> compResultClass,
                                   boolean fast)
                                                                                                               throws java.lang.InstantiationException,
                                                                                                                      java.lang.IllegalAccessException
Compare 2 versions using the specified class.

Parameters:
newVersion - New version to be compared.
oldVersion - Old version to compare to.
compResultClass - Class to use to compare objects in versions.
fast - Whether or not to run in fast mode, only determining if versions are the same or not.
Returns:
A ComparisonResult holding comparison information about the 2 versions.
Throws:
java.lang.IllegalAccessException
java.lang.InstantiationException

delete

public boolean delete(C id)
               throws java.io.IOException
Removes all versions of the given id.

Parameters:
id - ID to be deleted.
Returns:
True if ID was successfully deleted.
Throws:
java.io.IOException

deletedIds

public C[] deletedIds()
                                                       throws java.io.IOException
Retrieve list of IDs that have been deleted.

Returns:
All IDs deleted.
Throws:
java.io.IOException

deletedIdsSince

public C[] deletedIdsSince(long timestamp)
                                                            throws java.io.IOException
Retrieve a list of IDs that have been deleted since the given timestamp.

Parameters:
timestamp - Timestamp to use.
Returns:
All IDS deleted since the given timestamp.
Throws:
java.io.IOException

diff

public ComparisonResult<T> diff(C id,
                                Version<T> newVersion)
                                                                                                            throws java.lang.InstantiationException,
                                                                                                                   java.lang.IllegalAccessException,
                                                                                                                   java.io.IOException
Will perform a diff, trying to determine the class of the comparison result by appending ComparisonResult to the versionedObject classname.

Parameters:
id - ID of the item to which the version should be compared.
newVersion - Version to be compared.
Returns:
A ComparisonResult holding information about the comparison.
Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException
java.io.IOException

diff

public ComparisonResult<T> diff(C id,
                                Version<T> newVersion,
                                java.lang.Class<? extends ComparisonResult<? super T>> compResultClass)
                                                                                                            throws java.lang.InstantiationException,
                                                                                                                   java.lang.IllegalAccessException,
                                                                                                                   java.io.IOException
Compares the new version to the latest version of object with the given id. Will store the result in a new instance of the given class, which has to extend ComparisonResult.

Parameters:
id - ID of the item to which the version should be compared.
newVersion - Version to be compared.
compResultClass - Class to use for comparison.
Returns:
A ComparisonResult holding information about the comparison.
Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException
java.io.IOException

discard

public boolean discard(C id)
                throws java.io.IOException
Remove all version and do not keep ID in history.

Parameters:
id - ID to be deleted.
Returns:
True if ID was successfully discarded.
Throws:
java.io.IOException

discardChanges

public void discardChanges()
Discard all changes made since the last save.


fetch

public Version<T> fetch(C id,
                        int versionNum)
                                                                                                    throws java.io.IOException
Fetch the given version of object with the given id.

Parameters:
id - ID to retrieve.
versionNum - Version to retrieve.
Returns:
Given version of the item with ID specified.
Throws:
java.io.IOException

fetch

public Version<T>[] fetch(C id,
                          int[] versionNums)
                                                                                                      throws java.io.IOException
Fetch the given versions of object with the given id.

Parameters:
id - ID to retrieve.
versionNums - Versions to retrieve.
Returns:
Given versions of the item with ID specified.
Throws:
java.io.IOException

findComparisonResultClass

public java.lang.Class<? extends ComparisonResult<? super T>> findComparisonResultClass(Version<T> ver)
Find the Class to use for comparing this version, will replace "data" by "comp" in the package name and add "ComparisonResult" to the class of the versions's versioned object. If no suitable class is found, DefaultComparisonResult will be returned.

Parameters:
ver - Version for which to find a ComparisonResult class.
Returns:
The Class to be used to compare the object in this version.

getVersionRollover

public int getVersionRollover()
Retrieve the number of versions kept for historical purposes.

Returns:
Returns the versionRollover.

inUse

public boolean inUse(C id)
              throws java.io.IOException
Determine if the given id is already in use.

Parameters:
id - ID to verify.
Returns:
True if ID is in use, false otherwise.
Throws:
java.io.IOException

isClosed

public boolean isClosed()
Determine if the underlying container has already been closed.

Returns:
True if the underlying container has been closed.

latest

public Version<T> latest(C id)
                                                                                                     throws java.io.IOException
Fetch the latest version of the object with given id.

Parameters:
id - ID to retrieve.
Returns:
Latest version of the item with the given ID.
Throws:
java.io.IOException

latest

public Version<T> latest(C id,
                         int tstamp)
                                                                                                     throws java.io.IOException
Fetch the latest version of the object with given id before the given timestamp.

Parameters:
id - ID to retrieve.
tstamp - Timestamp to use.
Returns:
Latest version of the item with the given ID before the specified timestamp..
Throws:
java.io.IOException

latests

public Version<T>[] latests(C[] ids)
                                                                                                        throws java.io.IOException
Fetch the latest versions of every id specified.

Parameters:
ids - Array of IDs to retrieve.
Returns:
Array of latest versions for the given IDs, not necessarily in the same order.
Throws:
java.io.IOException

latests

public Version<T>[] latests(C[] ids,
                            int tstamp)
                                                                                                        throws java.io.IOException
Fetch the latest versions of every id specified before the given timestamp.

Parameters:
ids - Array of IDs to retrieve.
tstamp - Timestamp to use.
Returns:
Array of latest versions for the given IDs before the specified timestamp, not necessarily in the same order.
Throws:
java.io.IOException

listModifiedSince

public C[] listModifiedSince(long timestamp)
                                                              throws java.io.IOException
List the latest versions modified since the given timestamp.

Parameters:
timestamp -
Returns:
Array of the latest versions of items modified since specified timestamp.
Throws:
java.io.IOException

modifiedSince

public Version<T>[] modifiedSince(long timestamp)
                                                                                                              throws java.io.IOException
Fetch the latest versions modified since the given timestamp.

Parameters:
timestamp -
Returns:
Array of the latest versions of items modified since specified timestamp.
Throws:
java.io.IOException

saveChanges

public void saveChanges()
Save all changes in the container.


setVersionRollover

public void setVersionRollover(int versionRollover)
Set the number of versions kept for historical purposes.

Parameters:
versionRollover - The versionRollover to set.


Copyright © 2004-2007 Steve Molloy. All Rights Reserved.