KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > se > query > index > IndexBTreeImpl


1 /*
2  * Jalisto - JAva LIght STOrage
3  * Copyright (C) 2000-2005 Xcalia http://www.xcalia.com
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * Xcalia
20  * 71, rue Desnouettes
21  * 75014 Paris - France
22  * http://www.xcalia.com
23  */

24 package org.objectweb.jalisto.se.query.index;
25
26 import org.objectweb.jalisto.se.impl.LogicalOid;
27 import org.objectweb.jalisto.se.api.ClassDescription;
28 import org.objectweb.jalisto.se.api.query.FielComparator;
29 import org.objectweb.jalisto.se.api.query.Index;
30 import org.objectweb.jalisto.se.api.query.IndexManager;
31 import org.objectweb.jalisto.se.impl.InFileAddress;
32 import org.objectweb.jalisto.se.query.IndexManagerImpl;
33 import org.objectweb.jalisto.se.query.btree.BTree;
34
35 import java.util.Set JavaDoc;
36
37 public class IndexBTreeImpl implements Index {
38
39     public IndexBTreeImpl(InFileAddress ifa, int fieldIndex,
40                              ClassDescription meta, IndexManagerImpl indexManager) {
41 // System.out.println("Build a BTree index");
42
this.tree = new BTree(this, fieldIndex, meta, indexManager);
43         this.ifa = ifa;
44         this.className = meta.getClassName();
45         this.fieldName = meta.getFieldNames()[fieldIndex];
46     }
47
48     public Set JavaDoc get(Object JavaDoc key) {
49         return tree.getOidsFor(key);
50     }
51
52     public FielComparator getComparator() {
53         return tree.getComparator();
54     }
55
56     public Set JavaDoc keySet() {
57         return tree.getKeys();
58     }
59
60     public void put(Object JavaDoc key, LogicalOid value) {
61         tree.addOid(key, value);
62     }
63
64     public void remove(Object JavaDoc key, LogicalOid logicalOid) {
65         tree.removeOid(key, logicalOid);
66     }
67
68     public InFileAddress getIfa() {
69         return ifa;
70     }
71
72     public void setIndexManager(IndexManager indexManager) {
73         tree.setIndexManager((IndexManagerImpl) indexManager);
74     }
75
76     public void deleteIndex() {
77         tree.deleteTree();
78     }
79
80     public String JavaDoc toFullString() {
81         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
82         sb.append("IndexBTreeImpl on class ").append(className);
83         sb.append(" and field ").append(fieldName);
84         sb.append(":\n").append(tree);
85         return sb.toString();
86     }
87
88     public BTree getTree() {
89         return tree;
90     }
91
92     public String JavaDoc toString() {
93         return "IndexBTreeImpl(" + className + "," + fieldName + ")";
94     }
95
96     private InFileAddress ifa;
97     private BTree tree;
98     private String JavaDoc className;
99     private String JavaDoc fieldName;
100
101     public static final short TYPE = 1;
102 }
103
Popular Tags