de.topicmapslab.majortom.inmemory.store.revision
Class RevisionStore

java.lang.Object
  extended by de.topicmapslab.majortom.inmemory.store.revision.RevisionStore
All Implemented Interfaces:
IDataStore

public class RevisionStore
extends java.lang.Object
implements IDataStore

Store handling revisions

Author:
Sven Krosse

Field Summary
private  java.util.Map<java.lang.String,de.topicmapslab.majortom.model.revision.Changeset> associationChangesets
           
private  java.util.Map<de.topicmapslab.majortom.model.core.IAssociation,de.topicmapslab.majortom.model.revision.IRevisionChange> associationCreations
           
private  java.util.Map<java.lang.String,java.util.LinkedList<de.topicmapslab.majortom.model.revision.IRevision>> associationRevisions
           
private  java.util.Map<de.topicmapslab.majortom.model.revision.IRevision,de.topicmapslab.majortom.model.revision.Changeset> changesets
           
private  java.util.Map<de.topicmapslab.majortom.model.revision.IRevision,de.topicmapslab.majortom.model.event.TopicMapEventType> changesetTypes
           
private  long id
           
private  java.util.Calendar lastChange
           
private  java.util.Map<java.lang.String,de.topicmapslab.majortom.model.core.IConstruct> lazyCopies
           
private  java.util.Map<de.topicmapslab.majortom.model.revision.IRevision,java.util.Map<java.lang.String,java.lang.String>> metaData
           
private  java.util.List<de.topicmapslab.majortom.model.revision.IRevision> revisions
           
private  de.topicmapslab.majortom.model.store.ITopicMapStore store
           
private  java.util.Map<java.lang.String,java.util.Calendar> tags
           
private  java.util.Map<de.topicmapslab.majortom.model.revision.IRevision,java.util.Calendar> timestamps
           
private  java.util.Map<java.lang.String,de.topicmapslab.majortom.model.revision.Changeset> topicChangesets
           
private  java.util.Map<java.lang.String,java.util.LinkedList<de.topicmapslab.majortom.model.revision.IRevision>> topicRevisions
           
 
Constructor Summary
RevisionStore(de.topicmapslab.majortom.model.store.ITopicMapStore store)
          constructor
 
Method Summary
private  void addChange(de.topicmapslab.majortom.model.revision.IRevision revision, de.topicmapslab.majortom.model.revision.IRevisionChange change)
          Adding a new atomic change to the change set of the given revision
 void addChange(de.topicmapslab.majortom.model.revision.IRevision revision, de.topicmapslab.majortom.model.event.TopicMapEventType type, de.topicmapslab.majortom.model.core.IConstruct context, java.lang.Object newValue, java.lang.Object oldValue)
          Adding a new atomic change to the change set of the given revision
 void addMetaData(de.topicmapslab.majortom.model.revision.IRevision revision, java.lang.String key, java.lang.String value)
          Add the new key-value-pair to the meta data of the given revision
protected  void addRevision(de.topicmapslab.majortom.model.revision.IRevision revision, de.topicmapslab.majortom.model.event.TopicMapEventType type)
          Adding a new revision to the internal history
 void addTag(java.lang.String name)
          Adding a new tag for the current time stamp
 void addTag(java.lang.String name, java.util.Calendar calendar)
          Adding a new tag for the given time stamp.
 void close()
          Remove all items from the internal store.
 void createLazyCopy(de.topicmapslab.majortom.model.core.IAssociation association)
          Store a lazy copy of the given association
 void createLazyCopy(de.topicmapslab.majortom.model.core.IAssociationRole role)
          Store a lazy copy of the given association role
 void createLazyCopy(de.topicmapslab.majortom.model.core.IName name)
          Store a lazy copy of the given name
 void createLazyCopy(de.topicmapslab.majortom.model.core.IOccurrence occurrence)
          Store a lazy copy of the given occurrence
 void createLazyCopy(de.topicmapslab.majortom.model.core.ITopic topic)
          Store a lazy copy of the given topic
 void createLazyCopy(de.topicmapslab.majortom.model.core.IVariant variant)
          Store a lazy copy of the given variant
 de.topicmapslab.majortom.model.revision.IRevision createRevision(de.topicmapslab.majortom.model.event.TopicMapEventType type)
          Create a new revision and store them into the internal history
protected  RevisionChangeImpl createRevisionChange(de.topicmapslab.majortom.model.revision.IRevision revision, de.topicmapslab.majortom.model.event.TopicMapEventType type, de.topicmapslab.majortom.model.core.IConstruct context, java.lang.Object newValue, java.lang.Object oldValue)
          Method called to create a new revision change
 de.topicmapslab.majortom.model.revision.Changeset getAssociationChangeset(de.topicmapslab.majortom.model.core.ITopic associationType)
          Returns the changes set of all association items typed by the association type
 java.util.List<de.topicmapslab.majortom.model.revision.IRevision> getAssociationRevisions(de.topicmapslab.majortom.model.core.ITopic associationType)
          Returns all revisions of all association items typed by the association type
 de.topicmapslab.majortom.model.revision.Changeset getChangeset(de.topicmapslab.majortom.model.revision.IRevision revision)
          Returns the change set of the given revision
 de.topicmapslab.majortom.model.revision.Changeset getChangeset(de.topicmapslab.majortom.model.core.ITopic topic)
          Returns the changes set of the topic
 de.topicmapslab.majortom.model.event.TopicMapEventType getChangesetType(de.topicmapslab.majortom.model.revision.IRevision revision)
          Returns the internal store type of this revision
 de.topicmapslab.majortom.model.revision.IRevision getFirstRevision()
          Returns the first revision of the history
 java.util.Calendar getLastModification()
          Returns a time stamp representing the last change of the current topic map
 java.util.Calendar getLastModification(de.topicmapslab.majortom.model.core.ITopic topic)
          Returns a time stamp representing the last change of the given topic
 de.topicmapslab.majortom.model.revision.IRevision getLastRevision()
          Returns the last revision of the history
protected  java.util.Map<java.lang.String,de.topicmapslab.majortom.model.core.IConstruct> getLazyCopiesMap()
          Returns the internal reference of the lazy copy map
 de.topicmapslab.majortom.model.core.IConstruct getLazyCopy(java.lang.String id)
          Returns the lazy copy of the identified by the given id.
 java.util.Map<java.lang.String,java.lang.String> getMetaData(de.topicmapslab.majortom.model.revision.IRevision revision)
          Returns all meta data sets of the given revision as copy.
 java.lang.String getMetaData(de.topicmapslab.majortom.model.revision.IRevision revision, java.lang.String key)
          Returns the value of the meta set of the given revision identified by the given key
 de.topicmapslab.majortom.model.revision.IRevision getNextRevision(de.topicmapslab.majortom.model.revision.IRevision revision)
          Return the following revision of the given revision
 de.topicmapslab.majortom.model.revision.IRevision getPastRevision(de.topicmapslab.majortom.model.revision.IRevision revision)
          Return the previous revision of the given revision
 de.topicmapslab.majortom.model.revision.IRevision getRevision(java.util.Calendar timestamp)
          Returns the revision of the given time stamp.
 de.topicmapslab.majortom.model.revision.IRevision getRevision(long id)
          Returns the revision of the given id.
 de.topicmapslab.majortom.model.revision.IRevision getRevision(java.lang.String tag)
          Returns the revision of the given tag.
 java.util.List<de.topicmapslab.majortom.model.revision.IRevision> getRevisions(de.topicmapslab.majortom.model.core.ITopic topic)
          Returns all revisions of the topic
 java.util.Calendar getRevisionTimestamp(de.topicmapslab.majortom.model.revision.IRevision revision)
          Return the time stamp representing the beginning of the given revision
 boolean isLazyCopy(java.lang.String id)
          Checks if there is a lazy copy stored for this id by the internal store.
 void replace(de.topicmapslab.majortom.model.core.ITopic topic, de.topicmapslab.majortom.model.core.ITopic replacement, de.topicmapslab.majortom.model.revision.IRevision revision)
          Replace each reference of the given topic by the given replacement.
 void storeDependentRevision(de.topicmapslab.majortom.model.core.IAssociation association, de.topicmapslab.majortom.model.revision.IRevision revision)
          Store the given revision as a change-set containing at least one change of the given association.
 void storeDependentRevision(de.topicmapslab.majortom.model.core.ITopic topic, de.topicmapslab.majortom.model.revision.IRevision revision)
          Store the given revision as a change-set containing at least one change of the given topic.
 void storeDependentRevisionChanges(de.topicmapslab.majortom.model.core.IAssociation association, de.topicmapslab.majortom.model.revision.IRevisionChange change)
          Store the given revision change to the change set of the given association.
 void storeDependentRevisionChanges(de.topicmapslab.majortom.model.core.ITopic topic, de.topicmapslab.majortom.model.revision.IRevisionChange change)
          Store the given revision change to the change set of the given topic.
 org.w3c.dom.Document toXml()
          Exports the information of this history item as XML node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

topicRevisions

private java.util.Map<java.lang.String,java.util.LinkedList<de.topicmapslab.majortom.model.revision.IRevision>> topicRevisions

associationRevisions

private java.util.Map<java.lang.String,java.util.LinkedList<de.topicmapslab.majortom.model.revision.IRevision>> associationRevisions

associationCreations

private java.util.Map<de.topicmapslab.majortom.model.core.IAssociation,de.topicmapslab.majortom.model.revision.IRevisionChange> associationCreations

changesets

private java.util.Map<de.topicmapslab.majortom.model.revision.IRevision,de.topicmapslab.majortom.model.revision.Changeset> changesets

topicChangesets

private java.util.Map<java.lang.String,de.topicmapslab.majortom.model.revision.Changeset> topicChangesets

associationChangesets

private java.util.Map<java.lang.String,de.topicmapslab.majortom.model.revision.Changeset> associationChangesets

revisions

private java.util.List<de.topicmapslab.majortom.model.revision.IRevision> revisions

changesetTypes

private java.util.Map<de.topicmapslab.majortom.model.revision.IRevision,de.topicmapslab.majortom.model.event.TopicMapEventType> changesetTypes

timestamps

private java.util.Map<de.topicmapslab.majortom.model.revision.IRevision,java.util.Calendar> timestamps

tags

private java.util.Map<java.lang.String,java.util.Calendar> tags

lastChange

private java.util.Calendar lastChange

id

private long id

store

private final de.topicmapslab.majortom.model.store.ITopicMapStore store

lazyCopies

private java.util.Map<java.lang.String,de.topicmapslab.majortom.model.core.IConstruct> lazyCopies

metaData

private java.util.Map<de.topicmapslab.majortom.model.revision.IRevision,java.util.Map<java.lang.String,java.lang.String>> metaData
Constructor Detail

RevisionStore

public RevisionStore(de.topicmapslab.majortom.model.store.ITopicMapStore store)
constructor

Parameters:
store - the parent store
Method Detail

close

public void close()
Remove all items from the internal store.

Specified by:
close in interface IDataStore

addRevision

protected void addRevision(de.topicmapslab.majortom.model.revision.IRevision revision,
                           de.topicmapslab.majortom.model.event.TopicMapEventType type)
Adding a new revision to the internal history

Parameters:
revision - the new revision
type - the type of revision

getChangesetType

public de.topicmapslab.majortom.model.event.TopicMapEventType getChangesetType(de.topicmapslab.majortom.model.revision.IRevision revision)
Returns the internal store type of this revision

Parameters:
revision - the revision
Returns:
the type of changes

addChange

public void addChange(de.topicmapslab.majortom.model.revision.IRevision revision,
                      de.topicmapslab.majortom.model.event.TopicMapEventType type,
                      de.topicmapslab.majortom.model.core.IConstruct context,
                      java.lang.Object newValue,
                      java.lang.Object oldValue)
Adding a new atomic change to the change set of the given revision

Parameters:
revision - the revision
type - the kind of change
context - the context of change
newValue - the new value
oldValue - the old value

createRevisionChange

protected RevisionChangeImpl createRevisionChange(de.topicmapslab.majortom.model.revision.IRevision revision,
                                                  de.topicmapslab.majortom.model.event.TopicMapEventType type,
                                                  de.topicmapslab.majortom.model.core.IConstruct context,
                                                  java.lang.Object newValue,
                                                  java.lang.Object oldValue)
Method called to create a new revision change

Parameters:
revision - the revision
type - the type
context - the context
newValue - the new value
oldValue - the old value
Returns:
the generate revision change

addChange

private void addChange(de.topicmapslab.majortom.model.revision.IRevision revision,
                       de.topicmapslab.majortom.model.revision.IRevisionChange change)
Adding a new atomic change to the change set of the given revision

Parameters:
revision - the revision
change - the atomic change

storeDependentRevision

public void storeDependentRevision(de.topicmapslab.majortom.model.core.ITopic topic,
                                   de.topicmapslab.majortom.model.revision.IRevision revision)
Store the given revision as a change-set containing at least one change of the given topic.

Parameters:
topic - the topic
revision - the revision

storeDependentRevisionChanges

public void storeDependentRevisionChanges(de.topicmapslab.majortom.model.core.ITopic topic,
                                          de.topicmapslab.majortom.model.revision.IRevisionChange change)
Store the given revision change to the change set of the given topic.

Parameters:
topic - the topic
change - the revision change

storeDependentRevision

public void storeDependentRevision(de.topicmapslab.majortom.model.core.IAssociation association,
                                   de.topicmapslab.majortom.model.revision.IRevision revision)
Store the given revision as a change-set containing at least one change of the given association.

Parameters:
association - the association
revision - the revision

storeDependentRevisionChanges

public void storeDependentRevisionChanges(de.topicmapslab.majortom.model.core.IAssociation association,
                                          de.topicmapslab.majortom.model.revision.IRevisionChange change)
Store the given revision change to the change set of the given association.

Parameters:
association - the association
change - the revision change

getRevisionTimestamp

public java.util.Calendar getRevisionTimestamp(de.topicmapslab.majortom.model.revision.IRevision revision)
Return the time stamp representing the beginning of the given revision

Parameters:
revision - the revision
Returns:
the time stamp

getNextRevision

public de.topicmapslab.majortom.model.revision.IRevision getNextRevision(de.topicmapslab.majortom.model.revision.IRevision revision)
Return the following revision of the given revision

Parameters:
revision - the revision
Returns:
the following revision or null if this is the last revision

getPastRevision

public de.topicmapslab.majortom.model.revision.IRevision getPastRevision(de.topicmapslab.majortom.model.revision.IRevision revision)
Return the previous revision of the given revision

Parameters:
revision - the revision
Returns:
the previous revision or null if this is the first revision

replace

public void replace(de.topicmapslab.majortom.model.core.ITopic topic,
                    de.topicmapslab.majortom.model.core.ITopic replacement,
                    de.topicmapslab.majortom.model.revision.IRevision revision)
Replace each reference of the given topic by the given replacement.

Specified by:
replace in interface IDataStore
Parameters:
topic - the topic
replacement - the replacement
revision - the revision

addTag

public void addTag(java.lang.String name)
Adding a new tag for the current time stamp

Parameters:
name - the tag name

addTag

public void addTag(java.lang.String name,
                   java.util.Calendar calendar)
Adding a new tag for the given time stamp.

Parameters:
name - the tag name
calendar - the time stamp

getLastModification

public java.util.Calendar getLastModification()
Returns a time stamp representing the last change of the current topic map

Returns:
the lastChange

getLastModification

public java.util.Calendar getLastModification(de.topicmapslab.majortom.model.core.ITopic topic)
Returns a time stamp representing the last change of the given topic

Parameters:
topic - the topic
Returns:
the lastChange

getChangeset

public de.topicmapslab.majortom.model.revision.Changeset getChangeset(de.topicmapslab.majortom.model.revision.IRevision revision)
Returns the change set of the given revision

Parameters:
revision - the revision
Returns:
the change set

getFirstRevision

public de.topicmapslab.majortom.model.revision.IRevision getFirstRevision()
Returns the first revision of the history

Returns:
the first revision or null if history is empty

getLastRevision

public de.topicmapslab.majortom.model.revision.IRevision getLastRevision()
Returns the last revision of the history

Returns:
the last revision or null if history is empty

getRevision

public de.topicmapslab.majortom.model.revision.IRevision getRevision(java.util.Calendar timestamp)
Returns the revision of the given time stamp.

Parameters:
timestamp - the time stamp
Returns:
the revision

getRevision

public de.topicmapslab.majortom.model.revision.IRevision getRevision(java.lang.String tag)
Returns the revision of the given tag.

Parameters:
tag - the tag name
Returns:
the revision

getRevision

public de.topicmapslab.majortom.model.revision.IRevision getRevision(long id)
Returns the revision of the given id.

Parameters:
id - the id
Returns:
the revision

getRevisions

public java.util.List<de.topicmapslab.majortom.model.revision.IRevision> getRevisions(de.topicmapslab.majortom.model.core.ITopic topic)
Returns all revisions of the topic

Parameters:
topic - the topic
Returns:
the revisions

getChangeset

public de.topicmapslab.majortom.model.revision.Changeset getChangeset(de.topicmapslab.majortom.model.core.ITopic topic)
Returns the changes set of the topic

Parameters:
topic - the topic
Returns:
the changes set

getAssociationChangeset

public de.topicmapslab.majortom.model.revision.Changeset getAssociationChangeset(de.topicmapslab.majortom.model.core.ITopic associationType)
Returns the changes set of all association items typed by the association type

Parameters:
associationType - the association type
Returns:
the changes set

getAssociationRevisions

public java.util.List<de.topicmapslab.majortom.model.revision.IRevision> getAssociationRevisions(de.topicmapslab.majortom.model.core.ITopic associationType)
Returns all revisions of all association items typed by the association type

Parameters:
associationType - the association type
Returns:
the revisions

createRevision

public de.topicmapslab.majortom.model.revision.IRevision createRevision(de.topicmapslab.majortom.model.event.TopicMapEventType type)
Create a new revision and store them into the internal history

Parameters:
type - the type of internal change set for the new revision
Returns:
the revision

toXml

public org.w3c.dom.Document toXml()
                           throws de.topicmapslab.majortom.model.exception.TopicMapStoreException
Exports the information of this history item as XML node.

Returns:
the document
Throws:
de.topicmapslab.majortom.model.exception.TopicMapStoreException

createLazyCopy

public void createLazyCopy(de.topicmapslab.majortom.model.core.ITopic topic)
                    throws de.topicmapslab.majortom.model.exception.TopicMapStoreException
Store a lazy copy of the given topic

Parameters:
topic - the topic
Throws:
de.topicmapslab.majortom.model.exception.TopicMapStoreException - thrown if operation fails

createLazyCopy

public void createLazyCopy(de.topicmapslab.majortom.model.core.IOccurrence occurrence)
                    throws de.topicmapslab.majortom.model.exception.TopicMapStoreException
Store a lazy copy of the given occurrence

Parameters:
occurrence - the occurrence
Throws:
de.topicmapslab.majortom.model.exception.TopicMapStoreException - thrown if operation fails

createLazyCopy

public void createLazyCopy(de.topicmapslab.majortom.model.core.IName name)
                    throws de.topicmapslab.majortom.model.exception.TopicMapStoreException
Store a lazy copy of the given name

Parameters:
name - the name
Throws:
de.topicmapslab.majortom.model.exception.TopicMapStoreException - thrown if operation fails

createLazyCopy

public void createLazyCopy(de.topicmapslab.majortom.model.core.IVariant variant)
                    throws de.topicmapslab.majortom.model.exception.TopicMapStoreException
Store a lazy copy of the given variant

Parameters:
variant - the variant
Throws:
de.topicmapslab.majortom.model.exception.TopicMapStoreException - thrown if operation fails

createLazyCopy

public void createLazyCopy(de.topicmapslab.majortom.model.core.IAssociation association)
                    throws de.topicmapslab.majortom.model.exception.TopicMapStoreException
Store a lazy copy of the given association

Parameters:
association - the association
Throws:
de.topicmapslab.majortom.model.exception.TopicMapStoreException - thrown if operation fails

createLazyCopy

public void createLazyCopy(de.topicmapslab.majortom.model.core.IAssociationRole role)
                    throws de.topicmapslab.majortom.model.exception.TopicMapStoreException
Store a lazy copy of the given association role

Parameters:
role - the association role
Throws:
de.topicmapslab.majortom.model.exception.TopicMapStoreException - thrown if operation fails

isLazyCopy

public boolean isLazyCopy(java.lang.String id)
Checks if there is a lazy copy stored for this id by the internal store.

Parameters:
id - the id
Returns:
true if there is a lazy copy, false otherwise.

getLazyCopy

public de.topicmapslab.majortom.model.core.IConstruct getLazyCopy(java.lang.String id)
Returns the lazy copy of the identified by the given id.

Parameters:
id - the id
Returns:
the lazy copy or null if there is no lazy copy stored

addMetaData

public void addMetaData(de.topicmapslab.majortom.model.revision.IRevision revision,
                        java.lang.String key,
                        java.lang.String value)
Add the new key-value-pair to the meta data of the given revision

Parameters:
revision - the revision
key - the key of meta data
value - the value of meta data

getMetaData

public java.lang.String getMetaData(de.topicmapslab.majortom.model.revision.IRevision revision,
                                    java.lang.String key)
Returns the value of the meta set of the given revision identified by the given key

Parameters:
revision - the revision
key - the key
Returns:
the value or null if the key is unknown

getMetaData

public java.util.Map<java.lang.String,java.lang.String> getMetaData(de.topicmapslab.majortom.model.revision.IRevision revision)
Returns all meta data sets of the given revision as copy.

Parameters:
revision - the revision
Returns:
the copy of all meta data sets

getLazyCopiesMap

protected java.util.Map<java.lang.String,de.topicmapslab.majortom.model.core.IConstruct> getLazyCopiesMap()
Returns the internal reference of the lazy copy map

Returns:
the lazyCopies but never null