org.ceryle.wiki.plugin.assertion
Class AssertionQueryCache

java.lang.Object
  extended by org.ceryle.util.HashCache
      extended by org.ceryle.wiki.plugin.assertion.AssertionQueryCache
All Implemented Interfaces:
Map

public class AssertionQueryCache
extends HashCache

Extends HashCache as a cache for Assertion queries.

TODO: Currently this class does not manage cache dirtiness nor support AssertionQueryExecutor.getAssertions(), AssertionQueryExecutor.getAssertionCount(), or AssertionQueryExecutor.getAssertionTemplates() since it's not considered that these three methods will be called frequently by actual applications.

Version:
$Id: AssertionQueryCache.java,v 1.1 2007-06-15 12:10:13 altheim Exp $
Author:
Murray Altheim

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
AssertionQueryCache(WikiMapManager manager, AssertionQueryExecutor executor)
          Constructor for the AssertionQueryCache.
 
Method Summary
 Object get(Object key)
          Returns the value to which this map maps the specified key.
static String getQuerySignature(String pagename, String subject, String predicate, String object, int templateMode, int logicMode)
          Creates a base 64 signature from the provided query parameters.
 Object put(Object key, Object value)
          Associates the specified value with the specified key in this map.
 Collection queryAssertions(Collection associations, String pagename, String subject, String predicate, String object, int templateMode, int logicMode)
          The method that calls AssertionQueryExecutor with a getAssertions() query.
 boolean queryHasAssertion(String pagename, String subject, String predicate, String object, int templateMode, int logicMode)
          The method that calls AssertionQueryExecutor with a hasAssertion() query.
 void setEnabled(boolean enabled)
          Enables or disables the cache.
 
Methods inherited from class org.ceryle.util.HashCache
clear, contains, containsKey, containsValue, entrySet, equals, hashCode, isEmpty, keySet, putAll, rankOf, remove, setMaximumSize, size, trimCache, values
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AssertionQueryCache

public AssertionQueryCache(WikiMapManager manager,
                           AssertionQueryExecutor executor)
Constructor for the AssertionQueryCache.

Parameters:
manager - the WikiMapManager for the wiki's TopicMap.
executor - the AssertionqueryExecutor to execute queries.
Method Detail

setEnabled

public void setEnabled(boolean enabled)
Enables or disables the cache. When disabled, the cache acts as a pass-through filter.


get

public Object get(Object key)
Returns the value to which this map maps the specified key. Returns null if the map contains no mapping for this key. A return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

Overrides the superclass to do a check on the key being an instance of a String, throwing an IllegalArgumentException if not.

Specified by:
get in interface Map
Overrides:
get in class HashCache
Parameters:
key - key whose associated value is to be returned.
Returns:
the value to which this map maps the specified key, or null if the map contains no mapping for this key.
Throws:
ClassCastException - if the key is not a String.
NullPointerException - if the key is null.
See Also:
Map.get(Object)

put

public Object put(Object key,
                  Object value)
Associates the specified value with the specified key in this map. If the map previously contained a mapping for this key, the old value is replaced by the specified value. (A map m is said to contain a mapping for a key k if and only if m.containsKey(k) would return true.)

Overrides the superclass to do a check on the key being an instance of a String and the value being an instance of a Collection, throwing an IllegalArgumentException if not.

Specified by:
put in interface Map
Overrides:
put in class HashCache
Parameters:
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.
Returns:
previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values.
Throws:
UnsupportedOperationException - if the put operation is not supported by this map.
ClassCastException - if the class of the specified key or value prevents it from being stored in this map.
IllegalArgumentException - if some aspect of this key or value prevents it from being stored in this map.
NullPointerException - this map does not permit null keys or values, and the specified key or value is null.
See Also:
Map.put(Object,Object)

queryAssertions

public Collection queryAssertions(Collection associations,
                                  String pagename,
                                  String subject,
                                  String predicate,
                                  String object,
                                  int templateMode,
                                  int logicMode)
                           throws AssertionException,
                                  TopicMapException
The method that calls AssertionQueryExecutor with a getAssertions() query. This is used so that queries can be cached when caching is enabled.

Note that the cache can contain both Assertions and Collections.

Throws:
AssertionException
TopicMapException

queryHasAssertion

public boolean queryHasAssertion(String pagename,
                                 String subject,
                                 String predicate,
                                 String object,
                                 int templateMode,
                                 int logicMode)
                          throws AssertionQueryException
The method that calls AssertionQueryExecutor with a hasAssertion() query. This is used so that queries can be cached when caching is enabled.

Throws:
AssertionQueryException

getQuerySignature

public static String getQuerySignature(String pagename,
                                       String subject,
                                       String predicate,
                                       String object,
                                       int templateMode,
                                       int logicMode)
Creates a base 64 signature from the provided query parameters. This is similar to the signature created by Assertion.getSignature() but includes the template and logic modes that are part of the query.

See Also:
Base64Converter.toBase64(long)


The Ceryle Project. Copyright ©2001-2007 Murray Altheim, All Rights Reserved. See LICENSE included with distribution.