1 5 6 package com.jofti.tree; 7 8 import java.util.Collection ; 9 import java.util.Iterator ; 10 import java.util.Map ; 11 import java.util.Properties ; 12 13 import org.apache.commons.logging.Log; 14 import org.apache.commons.logging.LogFactory; 15 16 import com.jofti.api.IndexQuery; 17 import com.jofti.api.NameSpaceKey; 18 import com.jofti.btree.BTOperations; 19 import com.jofti.btree.BTree; 20 import com.jofti.btree.ValueObject; 21 import com.jofti.cache.adapter.NameSpaceWrapper; 22 import com.jofti.core.IParsedQuery; 23 import com.jofti.core.InternalIndex; 24 import com.jofti.core.QueryId; 25 import com.jofti.exception.JoftiException; 26 import com.jofti.introspect.ClassIntrospector; 27 import com.jofti.parser.ConvenienceQueryWrapper; 28 import com.jofti.parser.ParserManager; 29 import com.jofti.query.MatchInQuery; 30 import com.jofti.query.MatchNotQuery; 31 import com.jofti.query.MatchQuery; 32 import com.jofti.query.MatchRangeQuery; 33 import com.jofti.query.namespace.MatchNSInQuery; 34 import com.jofti.query.namespace.MatchNSLargerQuery; 35 import com.jofti.query.namespace.MatchNSNotQuery; 36 import com.jofti.query.namespace.MatchNSQuery; 37 import com.jofti.query.namespace.MatchNSRangeQuery; 38 import com.jofti.query.namespace.MatchNSSmallerQuery; 39 43 public class NameSpacedTreeIndex extends TreeIndex 44 { 45 46 47 private static Log log = LogFactory.getLog(NameSpacedTreeIndex.class); 48 49 50 51 52 public NameSpacedTreeIndex(){ 53 super(); 54 } 55 56 57 public NameSpacedTreeIndex(BTree tree, ClassIntrospector parser) 58 { 59 60 super(tree,parser); 61 62 63 64 } 65 66 public NameSpacedTreeIndex(BTree tree, ClassIntrospector parser, Map indexedDimensions) 67 { 68 69 super(tree,parser, indexedDimensions); 70 71 72 73 } 74 75 78 public void init(Properties props) throws JoftiException{ 79 tree.init(props); 80 engine = new NameSpacedTreeMatcherEngine(); 81 parserManager = new ParserManager(introspector); 83 this.treeAdapter = new NameSpaceTreeOperationAdapter(); 84 85 } 86 87 88 public Map query(IndexQuery query) throws JoftiException { 89 90 NameSpacedTreeMatcherEngine tempEngine = (NameSpacedTreeMatcherEngine)engine; 92 93 94 if (query == null){ 95 throw new JoftiException("Query object cannot be null"); 96 } 97 98 QueryId queryId = (QueryId)query; 99 100 switch(queryId.getQueryType().type){ 101 case 200 : 102 MatchNSQuery tempQuery = (MatchNSQuery)((ConvenienceQueryWrapper)query).getQuery(); 103 if (tempQuery.getPropertyName() ==null && tempQuery.getValue() == null){ 104 return tempEngine.matchNameSpace(tempQuery, this); 105 } else{ 106 return tempEngine.matchProperty(tempQuery, this); 107 } 108 case 201: 109 return tempEngine.matchPropertyRange((MatchNSRangeQuery) ((ConvenienceQueryWrapper)query).getQuery(), this); 110 case 202: 111 return tempEngine.matchNotProperty((MatchNSNotQuery) ((ConvenienceQueryWrapper)query).getQuery(), this); 112 case 0: 114 return tempEngine.processQuery((IParsedQuery)query, this); 115 case 203: 116 return tempEngine.matchProperty((MatchNSInQuery)((ConvenienceQueryWrapper)query).getQuery(), this); 117 default: 118 throw new JoftiException("Query type "+ query.getClass() + " cannot be used for Name Spaced IndexCache"); 119 120 } 121 122 123 } 124 125 130 public Collection getAllKeyEntriesFromTree() throws JoftiException { 131 132 return ((NameSpaceTreeOperationAdapter)treeAdapter).getAllValuesForDimension(tree,introspector); 133 } 134 135 136 137 138 139 } 140 | Popular Tags |