de.topicmapslab.majortom.index.core
Class BaseCachedTypeInstanceIndexImpl<E 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<E>
          extended by de.topicmapslab.majortom.index.core.BaseCachedTypeInstanceIndexImpl<E>
All Implemented Interfaces:
de.topicmapslab.majortom.model.event.ITopicMapListener, org.tmapi.index.Index
Direct Known Subclasses:
CachedTypeInstanceIndexImpl, PagedTypeInstanceIndexImpl

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

Implementation of the in-memory IPagedTypeInstanceIndex supporting paging

Author:
Sven Krosse

Field Summary
private  java.util.Map<TypeInstanceCacheKey,java.util.Collection<?>> cachedConstructs
          internal cache for typed constructs
private  java.util.Map<TypeInstanceCacheKey,java.lang.Long> cachedNumberOfConstructs
          internal cache for number of typed constructs
private  java.util.Map<TypeInstanceCacheKey,java.util.Collection<org.tmapi.core.Topic>> cachedTypes
          internal cache for types of constructs
private  java.util.Map<java.lang.Class<?>,java.util.Set<TypeInstanceCacheKey>> dependentCacheKeys
           
 
Constructor Summary
BaseCachedTypeInstanceIndexImpl(E store)
          constructor
 
Method Summary
protected  void cache(java.lang.Class<? extends de.topicmapslab.majortom.model.core.IConstruct> clazz, java.util.Collection<org.tmapi.core.Topic> values)
          Method store the types to the internal cache.
protected  void cache(java.lang.Class<? extends de.topicmapslab.majortom.model.core.IConstruct> clazz, java.lang.Integer offset, java.lang.Integer limit, java.util.Comparator<org.tmapi.core.Topic> comparator, java.util.Collection<org.tmapi.core.Topic> values)
          Method store the types to the internal cache.
protected
<T extends org.tmapi.core.Construct>
void
cache(java.lang.Class<? extends de.topicmapslab.majortom.model.core.IConstruct> clazz, java.lang.Object filter, java.lang.Boolean multiMatch, java.util.Collection<T> values)
          Method store the given values.
protected
<T extends org.tmapi.core.Construct>
void
cache(java.lang.Class<? extends de.topicmapslab.majortom.model.core.IConstruct> clazz, java.lang.Object filter, java.lang.Boolean multiMatch, java.lang.Integer offset, java.lang.Integer limit, java.util.Comparator<? extends org.tmapi.core.Construct> comparator, java.util.Collection<T> values)
          Method store the given values.
protected  void cacheNumberOfConstructs(java.lang.Class<? extends org.tmapi.core.Construct> clazz, java.lang.Object filter, java.lang.Boolean matchAll, long number)
          Store the number of matching construct into cache
 void clear()
          Removed any cached content from internal cache
 void clearCache()
          clear all internal caches
 void clearDependentCache(java.lang.Class<? extends de.topicmapslab.majortom.model.core.IConstruct>... classes)
          Method clears all caches depending on one of the given classes
 void close()
          
private  TypeInstanceCacheKey generateCacheKey(java.lang.Class<?> clazz, java.lang.Object filter, java.lang.Boolean multiMatch, java.lang.Integer offset, java.lang.Integer limit, java.util.Comparator<?> comparator)
          Generates a key for internal caching
private  java.util.Set<TypeInstanceCacheKey> getDependentKeys(java.lang.Class<?> clazz)
          Returns a set of cache keys dependents on the given type
 void open()
          
protected  java.util.Collection<org.tmapi.core.Topic> read(java.lang.Class<? extends org.tmapi.core.Construct> clazz)
          Method reads the constructs by their types from internal cache
protected  java.util.Collection<org.tmapi.core.Topic> read(java.lang.Class<? extends org.tmapi.core.Construct> clazz, java.lang.Integer offset, java.lang.Integer limit, java.util.Comparator<org.tmapi.core.Topic> comparator)
          Method reads the constructs by their types from internal cache
protected
<T extends org.tmapi.core.Construct>
java.util.Collection<T>
read(java.lang.Class<? extends de.topicmapslab.majortom.model.core.IConstruct> clazz, java.lang.Object filter, java.lang.Boolean multiMatch)
          Method reads constructs by their types from cache.
protected
<T extends org.tmapi.core.Construct>
java.util.Collection<T>
read(java.lang.Class<? extends de.topicmapslab.majortom.model.core.IConstruct> clazz, java.lang.Object filter, java.lang.Boolean multiMatch, java.lang.Integer offset, java.lang.Integer limit, java.util.Comparator<? extends org.tmapi.core.Construct> comparator)
          Method reads constructs by their types from cache.
protected  long readNumberOfConstructs(java.lang.Class<? extends org.tmapi.core.Construct> clazz, java.lang.Object filter, java.lang.Boolean matchAll)
          Reads the number of matching construct from cache if it exists
 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

dependentCacheKeys

private java.util.Map<java.lang.Class<?>,java.util.Set<TypeInstanceCacheKey>> dependentCacheKeys

cachedConstructs

private java.util.Map<TypeInstanceCacheKey,java.util.Collection<?>> cachedConstructs
internal cache for typed constructs


cachedNumberOfConstructs

private java.util.Map<TypeInstanceCacheKey,java.lang.Long> cachedNumberOfConstructs
internal cache for number of typed constructs


cachedTypes

private java.util.Map<TypeInstanceCacheKey,java.util.Collection<org.tmapi.core.Topic>> cachedTypes
internal cache for types of constructs

Constructor Detail

BaseCachedTypeInstanceIndexImpl

public BaseCachedTypeInstanceIndexImpl(E store)
constructor

Parameters:
store - the 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

public final void clearCache()
clear all internal caches

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

clearDependentCache

public final void clearDependentCache(java.lang.Class<? extends de.topicmapslab.majortom.model.core.IConstruct>... classes)
Method clears all caches depending on one of the given classes

Parameters:
classes - the classes

readNumberOfConstructs

protected long readNumberOfConstructs(java.lang.Class<? extends org.tmapi.core.Construct> clazz,
                                      java.lang.Object filter,
                                      java.lang.Boolean matchAll)
Reads the number of matching construct from cache if it exists

Parameters:
clazz - the class
filter - the filter
matchAll - the match all flag
Returns:
the number of constructs or -1

read

protected java.util.Collection<org.tmapi.core.Topic> read(java.lang.Class<? extends org.tmapi.core.Construct> clazz)
Method reads the constructs by their types from internal cache

Parameters:
clazz - the class
offset - the offset or null
limit - the limit or null
comparator - the comparator or null
Returns:
the types or null if the key-pairs is unknown

read

protected java.util.Collection<org.tmapi.core.Topic> read(java.lang.Class<? extends org.tmapi.core.Construct> clazz,
                                                          java.lang.Integer offset,
                                                          java.lang.Integer limit,
                                                          java.util.Comparator<org.tmapi.core.Topic> comparator)
Method reads the constructs by their types from internal cache

Parameters:
clazz - the class
offset - the offset or null
limit - the limit or null
comparator - the comparator or null
Returns:
the types or null if the key-pairs is unknown

cacheNumberOfConstructs

protected void cacheNumberOfConstructs(java.lang.Class<? extends org.tmapi.core.Construct> clazz,
                                       java.lang.Object filter,
                                       java.lang.Boolean matchAll,
                                       long number)
Store the number of matching construct into cache

Parameters:
clazz - the class
filter - the filter
matchAll - the match all flag
number - the number of constructs

cache

protected void cache(java.lang.Class<? extends de.topicmapslab.majortom.model.core.IConstruct> clazz,
                     java.util.Collection<org.tmapi.core.Topic> values)
Method store the types to the internal cache.

Parameters:
clazz - the class
values - the values to store

cache

protected void cache(java.lang.Class<? extends de.topicmapslab.majortom.model.core.IConstruct> clazz,
                     java.lang.Integer offset,
                     java.lang.Integer limit,
                     java.util.Comparator<org.tmapi.core.Topic> comparator,
                     java.util.Collection<org.tmapi.core.Topic> values)
Method store the types to the internal cache.

Parameters:
clazz - the class
offset - the offset or null
limit - the limit or null
comparator - the comparator or null
values - the values to store

read

protected <T extends org.tmapi.core.Construct> java.util.Collection<T> read(java.lang.Class<? extends de.topicmapslab.majortom.model.core.IConstruct> clazz,
                                                                            java.lang.Object filter,
                                                                            java.lang.Boolean multiMatch)
Method reads constructs by their types from cache.

Parameters:
clazz - the class
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 constructs or null if the key-pair is unknown

read

protected <T extends org.tmapi.core.Construct> java.util.Collection<T> read(java.lang.Class<? extends de.topicmapslab.majortom.model.core.IConstruct> clazz,
                                                                            java.lang.Object filter,
                                                                            java.lang.Boolean multiMatch,
                                                                            java.lang.Integer offset,
                                                                            java.lang.Integer limit,
                                                                            java.util.Comparator<? extends org.tmapi.core.Construct> comparator)
Method reads constructs by their types from cache.

Parameters:
clazz - the class
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 constructs or null if the key-pair is unknown

cache

protected <T extends org.tmapi.core.Construct> void cache(java.lang.Class<? extends de.topicmapslab.majortom.model.core.IConstruct> clazz,
                                                          java.lang.Object filter,
                                                          java.lang.Boolean multiMatch,
                                                          java.util.Collection<T> values)
Method store the given values.

Parameters:
clazz - the class
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 <T extends org.tmapi.core.Construct> void cache(java.lang.Class<? extends de.topicmapslab.majortom.model.core.IConstruct> clazz,
                                                          java.lang.Object filter,
                                                          java.lang.Boolean multiMatch,
                                                          java.lang.Integer offset,
                                                          java.lang.Integer limit,
                                                          java.util.Comparator<? extends org.tmapi.core.Construct> comparator,
                                                          java.util.Collection<T> values)
Method store the given values.

Parameters:
clazz - the class
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 TypeInstanceCacheKey generateCacheKey(java.lang.Class<?> clazz,
                                              java.lang.Object filter,
                                              java.lang.Boolean multiMatch,
                                              java.lang.Integer offset,
                                              java.lang.Integer limit,
                                              java.util.Comparator<?> comparator)
Generates a key for internal caching

Parameters:
clazz - the clazz
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;

getDependentKeys

private java.util.Set<TypeInstanceCacheKey> getDependentKeys(java.lang.Class<?> clazz)
Returns a set of cache keys dependents on the given type

Parameters:
type - the type
Returns:
all dependent keys

open

public void open()

Specified by:
open in interface org.tmapi.index.Index
Overrides:
open in class BaseCachedIndexImpl<E 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<E extends de.topicmapslab.majortom.model.store.ITopicMapStore>

clear

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

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