de.topicmapslab.majortom.database.transaction.cache
Class IdentityCache

java.lang.Object
  extended by de.topicmapslab.majortom.database.transaction.cache.IdentityCache
All Implemented Interfaces:
IDataStore

public class IdentityCache
extends java.lang.Object
implements IDataStore

Author:
Sven Krosse

Field Summary
private  java.util.Map<de.topicmapslab.majortom.model.core.IConstruct,java.util.Set<de.topicmapslab.majortom.model.core.ILocator>> constructItemIdentitiers
          construct to item-identifiers mapping
private  org.apache.commons.collections.BidiMap ids
          storage map of id-construct relation of the topic map engine
private  java.util.Map<de.topicmapslab.majortom.model.core.ILocator,de.topicmapslab.majortom.model.core.IConstruct> itemIdentitiers
          item-identifier mapping of the topic map engine
private  java.util.Set<de.topicmapslab.majortom.model.core.IScope> lazyScopes
           
private  java.util.Map<java.lang.String,de.topicmapslab.majortom.model.core.IConstruct> lazyStubs
           
private  java.util.Map<java.lang.String,de.topicmapslab.majortom.model.core.ILocator> locators
          storage map of the reference-locator mapping of the topic map
private  java.util.Set<java.lang.String> removedIds
           
private  java.util.Set<de.topicmapslab.majortom.model.core.ILocator> removedItemIdentifiers
          removed item-identifiers
private  java.util.Map<de.topicmapslab.majortom.model.core.ILocator,de.topicmapslab.majortom.model.core.ITopic> subjectIdentifiers
          subject-identifier mapping of the topic map engine
private  java.util.Map<de.topicmapslab.majortom.model.core.ILocator,de.topicmapslab.majortom.model.core.ITopic> subjectLocators
          subject-locator mapping of the topic map engine
private  TransactionTopicMapStore topicMapStore
          the parent store
private  java.util.Set<de.topicmapslab.majortom.model.core.ITopic> topics
          a set containing all topics
private  java.util.Map<de.topicmapslab.majortom.model.core.ITopic,java.util.Set<de.topicmapslab.majortom.model.core.ILocator>> topicSubjectIdentifiers
          topic to subject-identifiers mapping
private  java.util.Map<de.topicmapslab.majortom.model.core.ITopic,java.util.Set<de.topicmapslab.majortom.model.core.ILocator>> topicSubjectLocators
          topic to subject-locators mapping
 
Constructor Summary
IdentityCache(TransactionTopicMapStore topicMapStore)
          constructor
 
Method Summary
 void addItemIdentifer(de.topicmapslab.majortom.model.core.IConstruct c, de.topicmapslab.majortom.model.core.ILocator identifier)
          
 void addSubjectIdentifier(de.topicmapslab.majortom.model.core.ITopic t, de.topicmapslab.majortom.model.core.ILocator identifier)
          
 void addSubjectLocator(de.topicmapslab.majortom.model.core.ITopic t, de.topicmapslab.majortom.model.core.ILocator locator)
          
 de.topicmapslab.majortom.model.core.IConstruct byId(java.lang.String id)
          
 de.topicmapslab.majortom.model.core.IConstruct byItemIdentifier(de.topicmapslab.majortom.model.core.ILocator l)
          
 de.topicmapslab.majortom.model.core.ITopic bySubjectIdentifier(de.topicmapslab.majortom.model.core.ILocator l)
          
 de.topicmapslab.majortom.model.core.ITopic bySubjectLocator(de.topicmapslab.majortom.model.core.ILocator l)
          
 void close()
          Remove all items from the internal store.
protected  boolean containsConstruct(de.topicmapslab.majortom.model.core.IConstruct construct)
          Checks if the given construct is stored by the identity store.
 boolean containsIdentifier(de.topicmapslab.majortom.model.core.ILocator locator)
          Checks if the given locator is used as identifier.
 boolean containsItemIdentifier(de.topicmapslab.majortom.model.core.ILocator locator)
          Checks if the given locator is used as item-identifier.
protected  boolean containsItemIdentifiers(de.topicmapslab.majortom.model.core.IConstruct construct)
          Checks if the store know at least one item identifier for the given construct
 boolean containsSubjectIdentifier(de.topicmapslab.majortom.model.core.ILocator locator)
          Checks if the given locator is used as subject-identifier.
protected  boolean containsSubjectIdentifiers(de.topicmapslab.majortom.model.core.ITopic topic)
          Checks if the store know at least one subject identifier for the given topic
 boolean containsSubjectLocator(de.topicmapslab.majortom.model.core.ILocator locator)
          Checks if the given locator is used as subject-locator.
protected  boolean containsSubjectLocators(de.topicmapslab.majortom.model.core.ITopic topic)
          Checks if the store know at least one subject locator for the given topic
 de.topicmapslab.majortom.model.core.ILocator createItemIdentifier(de.topicmapslab.majortom.model.core.ITopicMap topicMap)
          Create a random item-identifier.
 de.topicmapslab.majortom.model.core.IScope createLazyStub(de.topicmapslab.majortom.model.core.IScope scope)
          Creates a lazy stub of the given scope
<T extends de.topicmapslab.majortom.model.core.IConstruct>
T
createLazyStub(T c)
          Creates a lazy stub of the given construct
 de.topicmapslab.majortom.model.core.ILocator createLocator(java.lang.String reference)
          Creates a new locator instance of the reference is unknown or return the stored instance
 java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getIdentifiers()
          Return all internal stored identifiers.
 java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getItemIdentifiers()
          Return all internal stored item-identifiers.
 java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getItemIdentifiers(de.topicmapslab.majortom.model.core.IConstruct c)
          
 java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getSubjectIdentifiers()
          Return all internal stored subject-identifiers.
 java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getSubjectIdentifiers(de.topicmapslab.majortom.model.core.ITopic t)
          
 java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getSubjectLocators()
          Return all internal stored subject-locators.
 java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getSubjectLocators(de.topicmapslab.majortom.model.core.ITopic t)
          
protected  ModifableTopicMapStoreImpl getTopicMapStore()
          Return the internal stored store instance.
 java.util.Set<de.topicmapslab.majortom.model.core.ITopic> getTopics()
          
 TransactionTopicMapStore getTransactionStore()
           
private  void internalAddItemIdentifer(de.topicmapslab.majortom.model.core.IConstruct c, de.topicmapslab.majortom.model.core.ILocator identifier)
          Internal method to register a item-identifier for the given construct
private  void internalAddSubjectIdentifier(de.topicmapslab.majortom.model.core.ITopic t, de.topicmapslab.majortom.model.core.ILocator identifier)
          Internal method to register a subject-identifier for the given topic
private  void internalAddSubjectLocator(de.topicmapslab.majortom.model.core.ITopic t, de.topicmapslab.majortom.model.core.ILocator locator)
          Internal method to register a subject-locator for the given topic
 boolean isRemovedConstruct(de.topicmapslab.majortom.model.core.IConstruct c)
          Checks if the given construct was deleted by the current transaction context.
 boolean isRemovedScope(de.topicmapslab.majortom.model.core.IScope scope)
          Checks if at least one theme of the given scope was deleted by the current transaction context.
 void removeConstruct(de.topicmapslab.majortom.model.core.IConstruct c)
          
 void removeItemIdentifer(de.topicmapslab.majortom.model.core.IConstruct c, de.topicmapslab.majortom.model.core.ILocator identifier)
          
 void removeSubjectIdentifier(de.topicmapslab.majortom.model.core.ITopic t, de.topicmapslab.majortom.model.core.ILocator identifier)
          
 void removeSubjectLocator(de.topicmapslab.majortom.model.core.ITopic t, de.topicmapslab.majortom.model.core.ILocator identifier)
          
 void removeTopic(de.topicmapslab.majortom.model.core.ITopic t)
          
 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 setId(de.topicmapslab.majortom.model.core.IConstruct c, java.lang.String id)
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

removedIds

private java.util.Set<java.lang.String> removedIds

lazyStubs

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

lazyScopes

private java.util.Set<de.topicmapslab.majortom.model.core.IScope> lazyScopes

removedItemIdentifiers

private java.util.Set<de.topicmapslab.majortom.model.core.ILocator> removedItemIdentifiers
removed item-identifiers


ids

private org.apache.commons.collections.BidiMap ids
storage map of id-construct relation of the topic map engine


locators

private java.util.Map<java.lang.String,de.topicmapslab.majortom.model.core.ILocator> locators
storage map of the reference-locator mapping of the topic map


itemIdentitiers

private java.util.Map<de.topicmapslab.majortom.model.core.ILocator,de.topicmapslab.majortom.model.core.IConstruct> itemIdentitiers
item-identifier mapping of the topic map engine


constructItemIdentitiers

private java.util.Map<de.topicmapslab.majortom.model.core.IConstruct,java.util.Set<de.topicmapslab.majortom.model.core.ILocator>> constructItemIdentitiers
construct to item-identifiers mapping


subjectIdentifiers

private java.util.Map<de.topicmapslab.majortom.model.core.ILocator,de.topicmapslab.majortom.model.core.ITopic> subjectIdentifiers
subject-identifier mapping of the topic map engine


topicSubjectIdentifiers

private java.util.Map<de.topicmapslab.majortom.model.core.ITopic,java.util.Set<de.topicmapslab.majortom.model.core.ILocator>> topicSubjectIdentifiers
topic to subject-identifiers mapping


subjectLocators

private java.util.Map<de.topicmapslab.majortom.model.core.ILocator,de.topicmapslab.majortom.model.core.ITopic> subjectLocators
subject-locator mapping of the topic map engine


topicSubjectLocators

private java.util.Map<de.topicmapslab.majortom.model.core.ITopic,java.util.Set<de.topicmapslab.majortom.model.core.ILocator>> topicSubjectLocators
topic to subject-locators mapping


topics

private java.util.Set<de.topicmapslab.majortom.model.core.ITopic> topics
a set containing all topics


topicMapStore

private final TransactionTopicMapStore topicMapStore
the parent store

Constructor Detail

IdentityCache

public IdentityCache(TransactionTopicMapStore topicMapStore)
constructor

Parameters:
topicMapStore - the transaction topic map store
Method Detail

addSubjectLocator

public void addSubjectLocator(de.topicmapslab.majortom.model.core.ITopic t,
                              de.topicmapslab.majortom.model.core.ILocator locator)


removeSubjectLocator

public void removeSubjectLocator(de.topicmapslab.majortom.model.core.ITopic t,
                                 de.topicmapslab.majortom.model.core.ILocator identifier)


getSubjectLocators

public java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getSubjectLocators(de.topicmapslab.majortom.model.core.ITopic t)


internalAddSubjectLocator

private void internalAddSubjectLocator(de.topicmapslab.majortom.model.core.ITopic t,
                                       de.topicmapslab.majortom.model.core.ILocator locator)
Internal method to register a subject-locator for the given topic

Parameters:
t - the topic
locator - the subject-locator

bySubjectLocator

public de.topicmapslab.majortom.model.core.ITopic bySubjectLocator(de.topicmapslab.majortom.model.core.ILocator l)


addSubjectIdentifier

public void addSubjectIdentifier(de.topicmapslab.majortom.model.core.ITopic t,
                                 de.topicmapslab.majortom.model.core.ILocator identifier)


internalAddSubjectIdentifier

private void internalAddSubjectIdentifier(de.topicmapslab.majortom.model.core.ITopic t,
                                          de.topicmapslab.majortom.model.core.ILocator identifier)
Internal method to register a subject-identifier for the given topic

Parameters:
t - the topic
identifier - the subject-identifier

removeSubjectIdentifier

public void removeSubjectIdentifier(de.topicmapslab.majortom.model.core.ITopic t,
                                    de.topicmapslab.majortom.model.core.ILocator identifier)


getSubjectIdentifiers

public java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getSubjectIdentifiers(de.topicmapslab.majortom.model.core.ITopic t)


bySubjectIdentifier

public de.topicmapslab.majortom.model.core.ITopic bySubjectIdentifier(de.topicmapslab.majortom.model.core.ILocator l)


addItemIdentifer

public void addItemIdentifer(de.topicmapslab.majortom.model.core.IConstruct c,
                             de.topicmapslab.majortom.model.core.ILocator identifier)


internalAddItemIdentifer

private void internalAddItemIdentifer(de.topicmapslab.majortom.model.core.IConstruct c,
                                      de.topicmapslab.majortom.model.core.ILocator identifier)
Internal method to register a item-identifier for the given construct

Parameters:
c - the construct
identifier - the item-identifier

removeItemIdentifer

public void removeItemIdentifer(de.topicmapslab.majortom.model.core.IConstruct c,
                                de.topicmapslab.majortom.model.core.ILocator identifier)


getItemIdentifiers

public java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getItemIdentifiers(de.topicmapslab.majortom.model.core.IConstruct c)


byItemIdentifier

public de.topicmapslab.majortom.model.core.IConstruct byItemIdentifier(de.topicmapslab.majortom.model.core.ILocator l)


removeTopic

public void removeTopic(de.topicmapslab.majortom.model.core.ITopic t)


removeConstruct

public void removeConstruct(de.topicmapslab.majortom.model.core.IConstruct c)


byId

public de.topicmapslab.majortom.model.core.IConstruct byId(java.lang.String id)


setId

public void setId(de.topicmapslab.majortom.model.core.IConstruct c,
                  java.lang.String id)


containsIdentifier

public boolean containsIdentifier(de.topicmapslab.majortom.model.core.ILocator locator)
Checks if the given locator is used as identifier.

Parameters:
locator - the identifier
Returns:
true if the locator is used as identifier, false otherwise.

containsItemIdentifier

public boolean containsItemIdentifier(de.topicmapslab.majortom.model.core.ILocator locator)
Checks if the given locator is used as item-identifier.

Parameters:
locator - the item-identifier
Returns:
true if the locator is used as item-identifier, false otherwise.

containsSubjectIdentifier

public boolean containsSubjectIdentifier(de.topicmapslab.majortom.model.core.ILocator locator)
Checks if the given locator is used as subject-identifier.

Parameters:
locator - the subject-identifier
Returns:
true if the locator is used as subject-identifier, false otherwise.

containsSubjectLocator

public boolean containsSubjectLocator(de.topicmapslab.majortom.model.core.ILocator locator)
Checks if the given locator is used as subject-locator.

Parameters:
locator - the subject-locator
Returns:
true if the locator is used as subject-locator, false otherwise.

getIdentifiers

public java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getIdentifiers()
Return all internal stored identifiers.

Returns:
all identifiers

getItemIdentifiers

public java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getItemIdentifiers()
Return all internal stored item-identifiers.

Returns:
all item-identifiers

getSubjectIdentifiers

public java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getSubjectIdentifiers()
Return all internal stored subject-identifiers.

Returns:
all subject-identifiers

getSubjectLocators

public java.util.Set<de.topicmapslab.majortom.model.core.ILocator> getSubjectLocators()
Return all internal stored subject-locators.

Returns:
all subject-locators

createLazyStub

public <T extends de.topicmapslab.majortom.model.core.IConstruct> T createLazyStub(T c)
                                                                        throws de.topicmapslab.majortom.model.exception.ConstructRemovedException
Creates a lazy stub of the given construct

Parameters:
c - the construct
Returns:
the lazy stub
Throws:
de.topicmapslab.majortom.model.exception.ConstructRemovedException - thrown if the id of the given construct is marked as removed

createLazyStub

public de.topicmapslab.majortom.model.core.IScope createLazyStub(de.topicmapslab.majortom.model.core.IScope scope)
                                                          throws de.topicmapslab.majortom.model.exception.ConstructRemovedException
Creates a lazy stub of the given scope

Parameters:
scope - the scope
Returns:
the lazy stub
Throws:
de.topicmapslab.majortom.model.exception.ConstructRemovedException - thrown if at least one contained theme is marked as removed

close

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

Specified by:
close in interface IDataStore

getTopics

public java.util.Set<de.topicmapslab.majortom.model.core.ITopic> getTopics()


containsConstruct

protected final boolean containsConstruct(de.topicmapslab.majortom.model.core.IConstruct construct)
Checks if the given construct is stored by the identity store.

Parameters:
construct - the construct
Returns:
true if the id is known by the store, false otherwise.

containsSubjectLocators

protected boolean containsSubjectLocators(de.topicmapslab.majortom.model.core.ITopic topic)
Checks if the store know at least one subject locator for the given topic

Parameters:
topic - the topic
Returns:
true if at least one subject locator is store for the given topic, false otherwise.

containsSubjectIdentifiers

protected boolean containsSubjectIdentifiers(de.topicmapslab.majortom.model.core.ITopic topic)
Checks if the store know at least one subject identifier for the given topic

Parameters:
topic - the topic
Returns:
true if at least one subject identifier is store for the given topic, false otherwise.

containsItemIdentifiers

protected boolean containsItemIdentifiers(de.topicmapslab.majortom.model.core.IConstruct construct)
Checks if the store know at least one item identifier for the given construct

Parameters:
construct - the construct
Returns:
true if at least one item identifier is store for the given construct, false otherwise.

isRemovedConstruct

public boolean isRemovedConstruct(de.topicmapslab.majortom.model.core.IConstruct c)
Checks if the given construct was deleted by the current transaction context.

Parameters:
c - the construct
Returns:
true if the construct was deleted by the current transaction, false otherwise.

isRemovedScope

public boolean isRemovedScope(de.topicmapslab.majortom.model.core.IScope scope)
Checks if at least one theme of the given scope was deleted by the current transaction context.

Parameters:
scope - the scope
Returns:
true if at least one theme of the given scope was deleted by the current transaction, false otherwise.

getTopicMapStore

protected ModifableTopicMapStoreImpl getTopicMapStore()
Return the internal stored store instance.

Returns:
the store the store instance

getTransactionStore

public TransactionTopicMapStore getTransactionStore()
Returns:
the topicMapStore

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

createLocator

public de.topicmapslab.majortom.model.core.ILocator createLocator(java.lang.String reference)
Creates a new locator instance of the reference is unknown or return the stored instance

Parameters:
reference - the reference
Returns:
the locator

createItemIdentifier

public de.topicmapslab.majortom.model.core.ILocator createItemIdentifier(de.topicmapslab.majortom.model.core.ITopicMap topicMap)
Create a random item-identifier.

Parameters:
topicMap - the topic map
Returns:
the item-identifier