001: /*
002: *
003: * Created on 01 June 2003, 08:32
004: */
005:
006: package com.jofti.tree;
007:
008: import java.util.Collection;
009: import java.util.Iterator;
010: import java.util.Map;
011: import java.util.Properties;
012:
013: import org.apache.commons.logging.Log;
014: import org.apache.commons.logging.LogFactory;
015:
016: import com.jofti.api.IndexQuery;
017: import com.jofti.api.NameSpaceKey;
018: import com.jofti.btree.BTOperations;
019: import com.jofti.btree.BTree;
020: import com.jofti.btree.ValueObject;
021: import com.jofti.cache.adapter.NameSpaceWrapper;
022: import com.jofti.core.IParsedQuery;
023: import com.jofti.core.InternalIndex;
024: import com.jofti.core.QueryId;
025: import com.jofti.exception.JoftiException;
026: import com.jofti.introspect.ClassIntrospector;
027: import com.jofti.parser.ConvenienceQueryWrapper;
028: import com.jofti.parser.ParserManager;
029: import com.jofti.query.MatchInQuery;
030: import com.jofti.query.MatchNotQuery;
031: import com.jofti.query.MatchQuery;
032: import com.jofti.query.MatchRangeQuery;
033: import com.jofti.query.namespace.MatchNSInQuery;
034: import com.jofti.query.namespace.MatchNSLargerQuery;
035: import com.jofti.query.namespace.MatchNSNotQuery;
036: import com.jofti.query.namespace.MatchNSQuery;
037: import com.jofti.query.namespace.MatchNSRangeQuery;
038: import com.jofti.query.namespace.MatchNSSmallerQuery;
039:
040: /**
041: *
042: * @author xenephon (xenephon@jofti.com)
043: */
044: public class NameSpacedTreeIndex extends TreeIndex {
045:
046: private static Log log = LogFactory
047: .getLog(NameSpacedTreeIndex.class);
048:
049: public NameSpacedTreeIndex() {
050: super ();
051: }
052:
053: public NameSpacedTreeIndex(BTree tree, ClassIntrospector parser) {
054:
055: super (tree, parser);
056:
057: }
058:
059: public NameSpacedTreeIndex(BTree tree, ClassIntrospector parser,
060: Map indexedDimensions) {
061:
062: super (tree, parser, indexedDimensions);
063:
064: }
065:
066: /* (non-Javadoc)
067: * @see com.jofti.tree.TreeIndex#init(java.util.Properties)
068: */
069: public void init(Properties props) throws JoftiException {
070: tree.init(props);
071: engine = new NameSpacedTreeMatcherEngine();
072: // start expiry clean up thread
073: parserManager = new ParserManager(introspector);
074: this .treeAdapter = new NameSpaceTreeOperationAdapter();
075:
076: }
077:
078: public Map query(IndexQuery query) throws JoftiException {
079:
080: // query lock is delegated to matching engine for this method
081: NameSpacedTreeMatcherEngine tempEngine = (NameSpacedTreeMatcherEngine) engine;
082:
083: if (query == null) {
084: throw new JoftiException("Query object cannot be null");
085: }
086:
087: QueryId queryId = (QueryId) query;
088:
089: switch (queryId.getQueryType().type) {
090: case 200:
091: MatchNSQuery tempQuery = (MatchNSQuery) ((ConvenienceQueryWrapper) query)
092: .getQuery();
093: if (tempQuery.getPropertyName() == null
094: && tempQuery.getValue() == null) {
095: return tempEngine.matchNameSpace(tempQuery, this );
096: } else {
097: return tempEngine.matchProperty(tempQuery, this );
098: }
099: case 201:
100: return tempEngine
101: .matchPropertyRange(
102: (MatchNSRangeQuery) ((ConvenienceQueryWrapper) query)
103: .getQuery(), this );
104: case 202:
105: return tempEngine.matchNotProperty(
106: (MatchNSNotQuery) ((ConvenienceQueryWrapper) query)
107: .getQuery(), this );
108: //common query type
109: case 0:
110: return tempEngine.processQuery((IParsedQuery) query, this );
111: case 203:
112: return tempEngine.matchProperty(
113: (MatchNSInQuery) ((ConvenienceQueryWrapper) query)
114: .getQuery(), this );
115: default:
116: throw new JoftiException("Query type " + query.getClass()
117: + " cannot be used for Name Spaced IndexCache");
118:
119: }
120:
121: }
122:
123: /**
124: * Gets a Collection of all the key entries.<p>
125: * @return a Collection
126: * @throws JoftiException
127: */
128: public Collection getAllKeyEntriesFromTree() throws JoftiException {
129:
130: return ((NameSpaceTreeOperationAdapter) treeAdapter)
131: .getAllValuesForDimension(tree, introspector);
132: }
133:
134: }
|