KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > inside > btree > FieldIndexKeyHandler


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o.inside.btree;
22
23 import com.db4o.*;
24 import com.db4o.foundation.*;
25 import com.db4o.inside.ix.*;
26
27
28 /**
29  * @exclude
30  */

31 public class FieldIndexKeyHandler implements Indexable4{
32     
33     private final Indexable4 _valueHandler;
34     
35     private final YInt _parentIdHandler;
36     
37     public FieldIndexKeyHandler(YapStream stream, Indexable4 delegate_) {
38         _parentIdHandler = new IDHandler(stream);
39         _valueHandler = delegate_;
40     }
41
42     public Object JavaDoc comparableObject(Transaction trans, Object JavaDoc indexEntry) {
43         throw new NotImplementedException();
44     }
45
46     public int linkLength() {
47         return _valueHandler.linkLength() + YapConst.INT_LENGTH;
48     }
49
50     public Object JavaDoc readIndexEntry(YapReader a_reader) {
51         // TODO: could read int directly here with a_reader.readInt()
52
int parentID = readParentID(a_reader);
53         Object JavaDoc objPart = _valueHandler.readIndexEntry(a_reader);
54         if (parentID < 0){
55             objPart = null;
56             parentID = - parentID;
57         }
58         return new FieldIndexKey(parentID, objPart);
59     }
60
61     private int readParentID(YapReader a_reader) {
62         return ((Integer JavaDoc)_parentIdHandler.readIndexEntry(a_reader)).intValue();
63     }
64
65     public void writeIndexEntry(YapReader writer, Object JavaDoc obj) {
66         FieldIndexKey composite = (FieldIndexKey)obj;
67         int parentID = composite.parentID();
68         Object JavaDoc value = composite.value();
69         if (value == null){
70             parentID = - parentID;
71         }
72         _parentIdHandler.write(parentID, writer);
73         _valueHandler.writeIndexEntry(writer, composite.value());
74     }
75     
76     public YapComparable prepareComparison(Object JavaDoc obj) {
77         FieldIndexKey composite = (FieldIndexKey)obj;
78         _valueHandler.prepareComparison(composite.value());
79         _parentIdHandler.prepareComparison(composite.parentID());
80         return this;
81     }
82
83     public int compareTo(Object JavaDoc obj) {
84         if (null == obj) {
85             throw new ArgumentNullException();
86         }
87         FieldIndexKey composite = (FieldIndexKey)obj;
88         int delegateResult = _valueHandler.compareTo(composite.value());
89         if(delegateResult != 0 ){
90             return delegateResult;
91         }
92         return _parentIdHandler.compareTo(composite.parentID());
93     }
94
95     public boolean isEqual(Object JavaDoc obj) {
96         throw new NotImplementedException();
97     }
98
99     public boolean isGreater(Object JavaDoc obj) {
100         throw new NotImplementedException();
101     }
102
103     public boolean isSmaller(Object JavaDoc obj) {
104         throw new NotImplementedException();
105     }
106
107     public Object JavaDoc current() {
108         return new FieldIndexKey(_parentIdHandler.currentInt(), _valueHandler.current());
109     }
110
111     public void defragIndexEntry(ReaderPair readers) {
112         _parentIdHandler.defragIndexEntry(readers);
113         _valueHandler.defragIndexEntry(readers);
114     }
115 }
116
117
Popular Tags