KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jofti > cache > IBaseAdaptor


1 package com.jofti.cache;
2
3 import java.util.Map JavaDoc;
4
5 import com.jofti.api.IndexQuery;
6 import com.jofti.core.IParsedQuery;
7 import com.jofti.core.InternalIndex;
8 import com.jofti.exception.JoftiException;
9 import com.jofti.introspect.ClassIntrospector;
10 import com.jofti.parser.ParserManager;
11
12 public interface IBaseAdaptor {
13
14     /**
15      * Gets a cache lock based on the mod of the hashcode of the key
16      * @param key
17      * @return - a lock Object
18      */

19     public abstract Object JavaDoc getCacheLock(Object JavaDoc key);
20
21     /*
22      * (non-Javadoc)
23      *
24      * @see com.jofti.api.IndexCache#query(com.jofti.api.IndexQuery)
25      */

26     public abstract Map JavaDoc query(IndexQuery query) throws JoftiException;
27
28     /**
29      * Takes a map containing the key values returned from the Index for the Query. The keys
30      * are the primary keys in the Cache.<p>
31      * This is the default implementation that loops through the returned keys and extracts the appropriate value
32      * from the Cache. This method is also responsible for checking if the value has changed since it was last
33      * indexed or if the value is no longer in the Cache excluding it from the returned results.<p>
34      *
35      * @param col A Map of result keys
36      * @return A Map of key/value results.
37      * @throws JoftiException Thrown if the retrieval from the cache throws an exception
38      */

39     public abstract Map JavaDoc getCacheValues(Map JavaDoc col, final IParsedQuery query,
40             final ClassIntrospector introspector) throws JoftiException;
41
42     /**
43      * Attempts to acquire an update lock for the cache. Multiple updates can run
44      * in parallel as the Index itself is threadsafe and the assumption is that the Cache is also.
45      * <p>
46      * However, queries and updates cannot run at the same time to prevent situations where if multiple
47      * nodes in the index are updated by one update then a query which runs at the same time may well misreport
48      * a match that should be returned if they were run in sequence.</p>
49      *
50      * @throws JoftiException
51      */

52     public abstract void acquireUpdateLock() throws JoftiException;
53
54     /**
55      * Releases an update lock.
56      */

57     public abstract void releaseUpdateLock();
58
59     /**
60      * Attempts to acquire a query lock for the cache. Multiple queries can run
61      * in parallel as the Index itself is threadsafe and the assumption is that the Cache is also.
62      * <p>
63      * However, queries and updates cannot run at the same time to prevent situations where if multiple
64      * nodes in the index are updated by one update then a query which runs at the same time may well misreport
65      * a match that should be returned if they were run in sequence.</p>
66      *
67      * @throws JoftiException
68      */

69     public abstract void acquireQueryLock() throws JoftiException;
70
71     /**
72      * Releases a query lock.
73      */

74     public abstract void releaseQueryLock();
75
76     /**
77      * A utility method that decorates a Cache key with a comparable wrapper if the key itself is not Comparable. This wrapper
78      * is not propogated into the Cache, but is used to wrap the key when placed in the Index.
79      *
80      * @param key
81      * @return Either an instance of a NonComparableKeyWrapper if the key is not Comparable or the original key object.
82      */

83     public abstract Object JavaDoc decorateKey(Object JavaDoc key);
84
85     /**
86      * A utility method that strips a decorated Cache key of its comparable wrapper if it has been previously decorated by the decorate method.
87      *
88      * @param key
89      * @return The object wrapped in a NonComparableKeyWrapper if wrapped or the original object if not.
90      */

91     public abstract Object JavaDoc stripKey(Object JavaDoc key);
92
93     /**
94      * Returns the Index instance from the adapter.
95      *
96      * @return the internal index implementation
97      */

98     public abstract InternalIndex getIndex();
99     
100     /**
101      * Normalises the query format for convenience queries or processes one the unparsed text query formats
102      * into its parsed form.
103      *
104      * @param query an unparsed query
105      * @param manager the Parser Manager that stores the mappings for the query
106      *
107      * @return the parsed query
108      */

109     public IndexQuery processQuery(IndexQuery query, ParserManager manager) throws JoftiException;
110     
111     
112     /**
113      * Takes a fully populated result set and applies any of the limiting steps defined in the
114      * maxResults or startResults. 0 for both values is considered a no-op. Negative values throw a runtime exception.
115      * a Start Value larger than the result original size will return no results, a maxResults large than the result size
116      * is reset to temp.size().
117      *
118      * @param temp the original result set
119      * @param startResult an int defining at which record the record set should begin
120      * @param maxResults an int defining the maximum number of records to return.
121      *
122      * @return the result set
123      */

124     public Map JavaDoc limitResults(Map JavaDoc temp, int startResult, int maxResults);
125         
126
127 }
Popular Tags