de.topicmapslab.majortom.index.core
Class BaseCachedSupertypeSubtypeIndexImpl<T extends de.topicmapslab.majortom.model.store.ITopicMapStore>

java.lang.Object
  extended by de.topicmapslab.majortom.index.IndexImpl<T>
      extended by de.topicmapslab.majortom.index.core.BaseCachedIndexImpl<T>
          extended by de.topicmapslab.majortom.index.core.BaseCachedSupertypeSubtypeIndexImpl<T>
All Implemented Interfaces:
de.topicmapslab.majortom.model.event.ITopicMapListener, org.tmapi.index.Index
Direct Known Subclasses:
CachedSupertypeSubtypeIndexImpl, PagedSupertypeSubtypeIndexImpl

public abstract class BaseCachedSupertypeSubtypeIndexImpl<T extends de.topicmapslab.majortom.model.store.ITopicMapStore>
extends BaseCachedIndexImpl<T>
implements de.topicmapslab.majortom.model.event.ITopicMapListener

Implementation of IPagedSupertypeSubtypeIndex.

Author:
Sven Krosse

Nested Class Summary
static class BaseCachedSupertypeSubtypeIndexImpl.Type
          enumeration to specify the type of type-hierarchy
 
Field Summary
private  java.util.Map<SupertypeSubtypeCacheKey,java.util.Collection<org.tmapi.core.Topic>> cache
           
private  java.util.Map<SupertypeSubtypeCacheKey,java.lang.Long> cacheNumberOfConstructs
           
 
Constructor Summary
BaseCachedSupertypeSubtypeIndexImpl(T store)
          constructor
 
Method Summary
protected  void cache(BaseCachedSupertypeSubtypeIndexImpl.Type type, java.lang.Object filter, java.lang.Boolean multiMatch, java.util.Collection<org.tmapi.core.Topic> values)
          Add the given values to the internal cache.
protected  void cache(BaseCachedSupertypeSubtypeIndexImpl.Type type, java.lang.Object filter, java.lang.Boolean multiMatch, java.lang.Integer offset, java.lang.Integer limit, java.util.Comparator<org.tmapi.core.Topic> comparator, java.util.Collection<org.tmapi.core.Topic> values)
          Add the given values to the internal cache.
protected  void cacheNumberOfConstructs(BaseCachedSupertypeSubtypeIndexImpl.Type type, java.lang.Object filter, java.lang.Boolean multiMatch, long number)
          Store the number of constructs into the cache
 void clear()
          Removed any cached content from internal cache
protected  void clearCache()
          Clear all caches
 void close()
          
private  SupertypeSubtypeCacheKey generateCacheKey(BaseCachedSupertypeSubtypeIndexImpl.Type type, java.lang.Object filter, java.lang.Boolean multiMatch, java.lang.Integer offset, java.lang.Integer limit, java.util.Comparator<org.tmapi.core.Topic> comparator)
          Generates a key for internal caching
 void open()
          
protected  java.util.Collection<org.tmapi.core.Topic> read(BaseCachedSupertypeSubtypeIndexImpl.Type type, java.lang.Object filter, java.lang.Boolean multiMatch)
          Internal method to read the type-hierarchy topics of the given type from cache.
protected  java.util.Collection<org.tmapi.core.Topic> read(BaseCachedSupertypeSubtypeIndexImpl.Type type, java.lang.Object filter, java.lang.Boolean multiMatch, java.lang.Integer offset, java.lang.Integer limit, java.util.Comparator<org.tmapi.core.Topic> comparator)
          Internal method to read the type-hierarchy topics of the given type from cache.
protected  long readNumberOfConstructs(BaseCachedSupertypeSubtypeIndexImpl.Type type, java.lang.Object filter, java.lang.Boolean multiMatch)
          Returns the number of constructs from the cache
 void topicMapChanged(java.lang.String id, de.topicmapslab.majortom.model.event.TopicMapEventType event, org.tmapi.core.Construct notifier, java.lang.Object newValue, java.lang.Object oldValue)
          
 
Methods inherited from class de.topicmapslab.majortom.index.core.BaseCachedIndexImpl
isCachingEnabled, isOnTransactionContext, isOnTransactionContext, isOnTransactionContext, isOnTransactionContext, isOnTransactionContext
 
Methods inherited from class de.topicmapslab.majortom.index.IndexImpl
getTopicMapStore, isAutoUpdated, isOpen, reindex
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cache

private java.util.Map<SupertypeSubtypeCacheKey,java.util.Collection<org.tmapi.core.Topic>> cache

cacheNumberOfConstructs

private java.util.Map<SupertypeSubtypeCacheKey,java.lang.Long> cacheNumberOfConstructs
Constructor Detail

BaseCachedSupertypeSubtypeIndexImpl

public BaseCachedSupertypeSubtypeIndexImpl(T store)
constructor

Parameters:
store - the internal topic map store
Method Detail

topicMapChanged

public void topicMapChanged(java.lang.String id,
                            de.topicmapslab.majortom.model.event.TopicMapEventType event,
                            org.tmapi.core.Construct notifier,
                            java.lang.Object newValue,
                            java.lang.Object oldValue)

Specified by:
topicMapChanged in interface de.topicmapslab.majortom.model.event.ITopicMapListener

clearCache

protected final void clearCache()
Clear all caches

Specified by:
clearCache in class BaseCachedIndexImpl<T extends de.topicmapslab.majortom.model.store.ITopicMapStore>

readNumberOfConstructs

protected long readNumberOfConstructs(BaseCachedSupertypeSubtypeIndexImpl.Type type,
                                      java.lang.Object filter,
                                      java.lang.Boolean multiMatch)
Returns the number of constructs from the cache

Parameters:
type - the type
filter - the filter
multiMatch - flag indicates if the filter is a collection of types if the result should match all types
Returns:
the number or -1

read

protected final java.util.Collection<org.tmapi.core.Topic> read(BaseCachedSupertypeSubtypeIndexImpl.Type type,
                                                                java.lang.Object filter,
                                                                java.lang.Boolean multiMatch)
Internal method to read the type-hierarchy topics of the given type from cache.

Parameters:
type - the type
filter - the filter criteria or null
multiMatch - flag indicates if the filter is a collection of types if the result should match all types
Returns:
the type-hierarchy topics of the given type from cache or null if key is unknown

read

protected final java.util.Collection<org.tmapi.core.Topic> read(BaseCachedSupertypeSubtypeIndexImpl.Type type,
                                                                java.lang.Object filter,
                                                                java.lang.Boolean multiMatch,
                                                                java.lang.Integer offset,
                                                                java.lang.Integer limit,
                                                                java.util.Comparator<org.tmapi.core.Topic> comparator)
Internal method to read the type-hierarchy topics of the given type from cache.

Parameters:
type - the type
filter - the filter criteria or null
multiMatch - flag indicates if the filter is a collection of types if the result should match all types
offset - the offset or null
limit - the limit or null
comparator - the comparator or null
Returns:
the type-hierarchy topics of the given type from cache or null if key is unknown

cacheNumberOfConstructs

protected void cacheNumberOfConstructs(BaseCachedSupertypeSubtypeIndexImpl.Type type,
                                       java.lang.Object filter,
                                       java.lang.Boolean multiMatch,
                                       long number)
Store the number of constructs into the cache

Parameters:
type - the type
filter - the filter
multiMatch - flag indicates if the filter is a collection of types if the result should match all types
number - the number

cache

protected final void cache(BaseCachedSupertypeSubtypeIndexImpl.Type type,
                           java.lang.Object filter,
                           java.lang.Boolean multiMatch,
                           java.util.Collection<org.tmapi.core.Topic> values)
Add the given values to the internal cache.

Parameters:
type - the type
filter - the filter criteria or null
multiMatch - flag indicates if the filter is a collection of types if the result should match all types
values - the values to store

cache

protected final void cache(BaseCachedSupertypeSubtypeIndexImpl.Type type,
                           java.lang.Object filter,
                           java.lang.Boolean multiMatch,
                           java.lang.Integer offset,
                           java.lang.Integer limit,
                           java.util.Comparator<org.tmapi.core.Topic> comparator,
                           java.util.Collection<org.tmapi.core.Topic> values)
Add the given values to the internal cache.

Parameters:
type - the type
filter - the filter criteria or null
multiMatch - flag indicates if the filter is a collection of types if the result should match all types
offset - the offset or null
limit - the limit or null
comparator - the comparator or null
values - the values to store

generateCacheKey

private SupertypeSubtypeCacheKey generateCacheKey(BaseCachedSupertypeSubtypeIndexImpl.Type type,
                                                  java.lang.Object filter,
                                                  java.lang.Boolean multiMatch,
                                                  java.lang.Integer offset,
                                                  java.lang.Integer limit,
                                                  java.util.Comparator<org.tmapi.core.Topic> comparator)
Generates a key for internal caching

Parameters:
type - the type
filter - the filter criteria or null
multiMatch - flag indicates if the filter is a collection of types if the result should match all types
offset - the offset or null
limit - the limit or null
comparator - the comparator or null
Returns:
the generated cache key;

open

public void open()

Specified by:
open in interface org.tmapi.index.Index
Overrides:
open in class BaseCachedIndexImpl<T extends de.topicmapslab.majortom.model.store.ITopicMapStore>

close

public void close()

Specified by:
close in interface org.tmapi.index.Index
Overrides:
close in class BaseCachedIndexImpl<T extends de.topicmapslab.majortom.model.store.ITopicMapStore>

clear

public void clear()
Removed any cached content from internal cache

Overrides:
clear in class BaseCachedIndexImpl<T extends de.topicmapslab.majortom.model.store.ITopicMapStore>