de.topicmapslab.majortom.index.core
Class BaseCachedIdentityIndexImpl<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.BaseCachedIdentityIndexImpl<T>
All Implemented Interfaces:
de.topicmapslab.majortom.model.event.ITopicMapListener, org.tmapi.index.Index
Direct Known Subclasses:
CachedIdentityIndexImpl, PagedIdentityIndexImpl

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

Implementation of IIdentityIndex

Author:
Sven Krosse

Nested Class Summary
static class BaseCachedIdentityIndexImpl.Type
          enumeration representing the map keys
 
Field Summary
private  java.util.Map<IdentityCacheKey,java.util.Collection<? extends org.tmapi.core.Construct>> cachedConstructs
           
private  java.util.Map<IdentityCacheKey,java.util.Collection<org.tmapi.core.Locator>> cachedIdentifiers
           
private  java.util.Map<BaseCachedIdentityIndexImpl.Type,java.lang.Long> cachedNumberOfIdentifiers
           
private  java.util.Map<BaseCachedIdentityIndexImpl.Type,java.util.Set<IdentityCacheKey>> dependentCacheKeys
           
 
Constructor Summary
BaseCachedIdentityIndexImpl(T store)
          constructor
 
Method Summary
protected  void cache(BaseCachedIdentityIndexImpl.Type type, long number)
          Store the number of identifiers
protected
<X extends org.tmapi.core.Construct>
void
cache(BaseCachedIdentityIndexImpl.Type type, java.util.regex.Pattern filter, java.util.Collection<X> constructs)
          Store the given values into the internal cache using the given key values.
protected
<X extends org.tmapi.core.Construct>
void
cache(BaseCachedIdentityIndexImpl.Type type, java.util.regex.Pattern filter, java.lang.Integer offset, java.lang.Integer limit, java.util.Comparator<X> comparator, java.util.Collection<X> constructs)
          Store the given values into the internal cache using the given key values.
protected  void cacheLocators(BaseCachedIdentityIndexImpl.Type type, java.util.Collection<org.tmapi.core.Locator> values)
          Store the given values into internal cache.
protected  void cacheLocators(BaseCachedIdentityIndexImpl.Type type, java.lang.Integer offset, java.lang.Integer limit, java.util.Comparator<org.tmapi.core.Locator> comparator, java.util.Collection<org.tmapi.core.Locator> values)
          Store the given values into internal cache.
protected  void cacheLocators(BaseCachedIdentityIndexImpl.Type type, java.util.regex.Pattern filter, java.util.Collection<org.tmapi.core.Locator> values)
          Store the given values into internal cache.
protected  void cacheLocators(BaseCachedIdentityIndexImpl.Type type, java.util.regex.Pattern filter, java.lang.Integer offset, java.lang.Integer limit, java.util.Comparator<org.tmapi.core.Locator> comparator, java.util.Collection<org.tmapi.core.Locator> values)
          Store the given values into internal cache.
 void clear()
          Removed any cached content from internal cache
protected  void clearCache()
          Clear all caches
private  void clearDependentCache(BaseCachedIdentityIndexImpl.Type... types)
          Clear all caches depend on the given types
 void close()
          
private  IdentityCacheKey generateCacheKey(BaseCachedIdentityIndexImpl.Type type, java.lang.Object filter, java.lang.Integer offset, java.lang.Integer limit, java.util.Comparator<?> comparator)
          Generates a key for internal caching
private  java.util.Set<IdentityCacheKey> getDependentKeys(BaseCachedIdentityIndexImpl.Type type)
          Returns a set of cache keys dependents on the given type
 void open()
          
protected  long read(BaseCachedIdentityIndexImpl.Type type)
          Returns the cached number of identifiers
protected
<X extends org.tmapi.core.Construct>
java.util.Collection<X>
read(BaseCachedIdentityIndexImpl.Type type, java.util.regex.Pattern filter)
          Internal method to read all identifiers of a specific type matching the given pattern.
protected
<X extends org.tmapi.core.Construct>
java.util.Collection<X>
read(BaseCachedIdentityIndexImpl.Type type, java.util.regex.Pattern filter, java.lang.Integer offset, java.lang.Integer limit, java.util.Comparator<X> comparator)
          Internal method to read all identifiers of a specific type matching the given pattern.
protected  java.util.Collection<org.tmapi.core.Locator> readLocators(BaseCachedIdentityIndexImpl.Type type)
          Internal method to read all identifiers of a specific type from cache.
protected  java.util.Collection<org.tmapi.core.Locator> readLocators(BaseCachedIdentityIndexImpl.Type type, java.lang.Integer offset, java.lang.Integer limit, java.util.Comparator<org.tmapi.core.Locator> comparator)
          Internal method to read all identifiers of a specific type from cache.
protected  java.util.Collection<org.tmapi.core.Locator> readLocators(BaseCachedIdentityIndexImpl.Type type, java.util.regex.Pattern filter)
          Internal method to read all identifiers of a specific type from cache.
protected  java.util.Collection<org.tmapi.core.Locator> readLocators(BaseCachedIdentityIndexImpl.Type type, java.util.regex.Pattern filter, java.lang.Integer offset, java.lang.Integer limit, java.util.Comparator<org.tmapi.core.Locator> comparator)
          Internal method to read all identifiers of a specific type from 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

cachedNumberOfIdentifiers

private java.util.Map<BaseCachedIdentityIndexImpl.Type,java.lang.Long> cachedNumberOfIdentifiers

cachedIdentifiers

private java.util.Map<IdentityCacheKey,java.util.Collection<org.tmapi.core.Locator>> cachedIdentifiers

cachedConstructs

private java.util.Map<IdentityCacheKey,java.util.Collection<? extends org.tmapi.core.Construct>> cachedConstructs

dependentCacheKeys

private java.util.Map<BaseCachedIdentityIndexImpl.Type,java.util.Set<IdentityCacheKey>> dependentCacheKeys
Constructor Detail

BaseCachedIdentityIndexImpl

public BaseCachedIdentityIndexImpl(T store)
constructor

Parameters:
store - the 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 void clearCache()
Clear all caches

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

clearDependentCache

private void clearDependentCache(BaseCachedIdentityIndexImpl.Type... types)
Clear all caches depend on the given types

Parameters:
types - the types

readLocators

protected final java.util.Collection<org.tmapi.core.Locator> readLocators(BaseCachedIdentityIndexImpl.Type type)
Internal method to read all identifiers of a specific type from cache.

Parameters:
type - the type
Returns:
the identifiers or null if key is unknown.

readLocators

protected final java.util.Collection<org.tmapi.core.Locator> readLocators(BaseCachedIdentityIndexImpl.Type type,
                                                                          java.lang.Integer offset,
                                                                          java.lang.Integer limit,
                                                                          java.util.Comparator<org.tmapi.core.Locator> comparator)
Internal method to read all identifiers of a specific type from cache.

Parameters:
type - the type
offset - the offset or null
limit - the limit or null
comparator - the comparator or null
Returns:
the identifiers or null if key is unknown.

readLocators

protected final java.util.Collection<org.tmapi.core.Locator> readLocators(BaseCachedIdentityIndexImpl.Type type,
                                                                          java.util.regex.Pattern filter)
Internal method to read all identifiers of a specific type from cache.

Parameters:
type - the type
filter - the filter criteria or null
Returns:
the identifiers or null if key is unknown.

readLocators

protected final java.util.Collection<org.tmapi.core.Locator> readLocators(BaseCachedIdentityIndexImpl.Type type,
                                                                          java.util.regex.Pattern filter,
                                                                          java.lang.Integer offset,
                                                                          java.lang.Integer limit,
                                                                          java.util.Comparator<org.tmapi.core.Locator> comparator)
Internal method to read all identifiers of a specific type from cache.

Parameters:
type - the type
filter - the filter criteria or null
offset - the offset or null
limit - the limit or null
comparator - the comparator or null
Returns:
the identifiers or null if key is unknown.

cacheLocators

protected final void cacheLocators(BaseCachedIdentityIndexImpl.Type type,
                                   java.util.Collection<org.tmapi.core.Locator> values)
Store the given values into internal cache.

Parameters:
type - the type
values - the locators to store

cacheLocators

protected final void cacheLocators(BaseCachedIdentityIndexImpl.Type type,
                                   java.lang.Integer offset,
                                   java.lang.Integer limit,
                                   java.util.Comparator<org.tmapi.core.Locator> comparator,
                                   java.util.Collection<org.tmapi.core.Locator> values)
Store the given values into internal cache.

Parameters:
type - the type
offset - the offset or null
limit - the limit or null
comparator - the comparator or null
values - the locators to store

cacheLocators

protected final void cacheLocators(BaseCachedIdentityIndexImpl.Type type,
                                   java.util.regex.Pattern filter,
                                   java.util.Collection<org.tmapi.core.Locator> values)
Store the given values into internal cache.

Parameters:
type - the type
filter - the filter criteria or null
values - the locators to store

cacheLocators

protected final void cacheLocators(BaseCachedIdentityIndexImpl.Type type,
                                   java.util.regex.Pattern filter,
                                   java.lang.Integer offset,
                                   java.lang.Integer limit,
                                   java.util.Comparator<org.tmapi.core.Locator> comparator,
                                   java.util.Collection<org.tmapi.core.Locator> values)
Store the given values into internal cache.

Parameters:
type - the type
filter - the filter criteria or null
offset - the offset or null
limit - the limit or null
comparator - the comparator or null
values - the locators to store

cache

protected final void cache(BaseCachedIdentityIndexImpl.Type type,
                           long number)
Store the number of identifiers

Parameters:
type - the type
number - the number

cache

protected final <X extends org.tmapi.core.Construct> void cache(BaseCachedIdentityIndexImpl.Type type,
                                                                java.util.regex.Pattern filter,
                                                                java.util.Collection<X> constructs)
Store the given values into the internal cache using the given key values.

Parameters:
type - the type
filter - the filter criteria or null
offset - the offset or null
limit - the limit or null
comparator - the comparator or null
values - the value to cache

cache

protected final <X extends org.tmapi.core.Construct> void cache(BaseCachedIdentityIndexImpl.Type type,
                                                                java.util.regex.Pattern filter,
                                                                java.lang.Integer offset,
                                                                java.lang.Integer limit,
                                                                java.util.Comparator<X> comparator,
                                                                java.util.Collection<X> constructs)
Store the given values into the internal cache using the given key values.

Parameters:
type - the type
filter - the filter criteria or null
offset - the offset or null
limit - the limit or null
comparator - the comparator or null
values - the value to cache

read

protected final long read(BaseCachedIdentityIndexImpl.Type type)
Returns the cached number of identifiers

Parameters:
type - the type
Returns:
the cached number or -1

read

protected final <X extends org.tmapi.core.Construct> java.util.Collection<X> read(BaseCachedIdentityIndexImpl.Type type,
                                                                                  java.util.regex.Pattern filter)
Internal method to read all identifiers of a specific type matching the given pattern.

Parameters:
type - the type
Returns:
the constructs or null if the key is unknown

read

protected final <X extends org.tmapi.core.Construct> java.util.Collection<X> read(BaseCachedIdentityIndexImpl.Type type,
                                                                                  java.util.regex.Pattern filter,
                                                                                  java.lang.Integer offset,
                                                                                  java.lang.Integer limit,
                                                                                  java.util.Comparator<X> comparator)
Internal method to read all identifiers of a specific type matching the given pattern.

Parameters:
type - the type
offset - the offset or null
limit - the limit or null
comparator - the comparator or null
Returns:
the constructs or null if the key is unknown

generateCacheKey

private IdentityCacheKey generateCacheKey(BaseCachedIdentityIndexImpl.Type type,
                                          java.lang.Object filter,
                                          java.lang.Integer offset,
                                          java.lang.Integer limit,
                                          java.util.Comparator<?> comparator)
Generates a key for internal caching

Parameters:
type - the type
filter - the filter criteria or null
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<IdentityCacheKey> getDependentKeys(BaseCachedIdentityIndexImpl.Type type)
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<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>