KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > core > storage > wizardStore > IDTable


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id: IDTable.java,v 1.2 2004/01/09 23:43:05 per_nyfelt Exp $
8

9 package org.ozoneDB.core.storage.wizardStore;
10
11 import java.io.IOException JavaDoc;
12
13 import org.ozoneDB.DxLib.*;
14 import org.ozoneDB.core.Env;
15 import org.ozoneDB.core.ObjectID;
16 import org.ozoneDB.core.storage.ClusterID;
17 import org.ozoneDB.util.LogWriter;
18
19
20 /**
21  * @author <a HREF="http://www.softwarebuero.de/">SMB</a>
22  * @version $Revision: 1.2 $Date: 2004/01/09 23:43:05 $
23  */

24 public final class IDTable extends DxDiskHashMap {
25
26     final static long serialVersionUID = 1L;
27
28     public final static int MAX_CACHE_SIZE = 2000;
29
30     // protected DxDeque leafCache;
31
//
32
// protected DxDeque branchCache;
33
//
34
// protected DxDeque keyDataCache;
35

36
37     public IDTable(String JavaDoc _baseFileName, int _maxBufferSize, int _cacheBits, int[] _tableBitSizes) {
38         super(_baseFileName, _maxBufferSize, _cacheBits, _tableBitSizes);
39         // leafCache = new DxArrayDeque (MAX_CACHE_SIZE);
40
// branchCache = new DxArrayDeque (MAX_CACHE_SIZE);
41
// keyDataCache = new DxArrayDeque (MAX_CACHE_SIZE);
42
}
43
44
45     public synchronized void close() throws Exception JavaDoc {
46         writeDirtyTables();
47         setReusable(true);
48     }
49
50
51     public synchronized void writeDirtyTables() throws IOException JavaDoc {
52         DxIterator it = buffer.iterator();
53         DxDiskSubTable table = null;
54         while ((table = (DxDiskSubTable) it.next()) != null) {
55             if (table.isDirty()) {
56                 if (false) {
57                     Env.currentEnv().logWriter.newEntry(this, "write dirty table: " + table.getFile(), LogWriter.DEBUG);
58                 }
59                 table.writeTable();
60             }
61         }
62     }
63
64
65     public boolean isDirtyTable(DxDiskSubTable table) {
66         boolean result = table.isDirty();
67         if (false) {
68             Env.currentEnv().logWriter.newEntry(this, "isDirtyTable(): name=" + table.getFile() + ", dirty=" + result, LogWriter.DEBUG);
69         }
70         return result;
71     }
72
73
74     public void printStatistics() {
75         Env.currentEnv().logWriter.newEntry(this, "Statistics:", LogWriter.INFO);
76         Env.currentEnv().logWriter.newEntry(this, " sub-table accesses: " + bufferAccesses + " hits: " + bufferHits + " loads: " + (bufferAccesses - bufferHits), LogWriter.INFO);
77         Env.currentEnv().logWriter.newEntry(this, " cache accesses: " + cacheAccesses + " hits: " + cacheHits, LogWriter.INFO);
78     }
79
80
81     public DxDiskHashNodeLeaf newNodeLeaf() {
82         return new IDTableNodeLeaf(this);
83
84         // System.out.print ("newNodeLeaf()... ");
85
// if (leafCache.isEmpty()) {
86
// System.out.println ("new");
87
// return new IDTableNodeLeaf (this);
88
// }
89
// else {
90
// System.out.println ("cache");
91
// return (DxDiskHashNodeLeaf)leafCache.popTop();
92
// }
93
}
94
95
96     public DxDiskHashNodeBranch newNodeBranch() {
97         return new IDTableNodeBranch(this);
98
99         // System.out.print ("newNodeBranch()... ");
100
// if (branchCache.isEmpty()) {
101
// System.out.println ("new");
102
// return new IDTableNodeBranch();
103
// }
104
// else {
105
// System.out.println ("cache");
106
// return (DxDiskHashNodeBranch)branchCache.popTop();
107
// }
108
}
109
110
111     public DxKeyData newKeyData() {
112         return new DxKeyData();
113
114         // System.out.print ("newKeyData()... ");
115
// if (keyDataCache.isEmpty()) {
116
// System.out.println ("new");
117
// return new DxKeyData();
118
// }
119
// else {
120
// System.out.println ("cache");
121
// return (DxKeyData)keyDataCache.popTop();
122
// }
123
}
124
125
126     public ObjectID newObjectID() {
127         // System.out.println ("newObjectID()");
128
return new ObjectID();
129     }
130
131
132     public ClusterID newClusterID() {
133         // System.out.println ("newClusterID()");
134
return new ClusterID();
135     }
136
137
138     /**
139      * The specified sub-table was deleted from the tree. So we have
140      * to delete it from the table buffer too.
141      */

142     public synchronized void deleteRequest(DxDiskSubTable subTable) {
143         // System.out.println ("deleteRequest()");
144
//
145
// DxDiskHashNode[] table = subTable.table();
146
// for (int i=0; i<table.length; i++) {
147
// if (table[i] instanceof IDTableNodeLeaf) {
148
// DxKeyData element = ((IDTableNodeLeaf)table[i]).element();
149
// while (element != null) {
150
// if (keyDataCache.count() < MAX_CACHE_SIZE) {
151
// System.out.print ("keydata cached");
152
// keyDataCache.pushTop (element);
153
// element = element.next;
154
// }
155
// else
156
// System.out.print ("keydata cache full");
157
// }
158
//
159
// if (leafCache.count() < MAX_CACHE_SIZE) {
160
// System.out.print ("leaf cached");
161
// leafCache.pushTop (table[i]);
162
// table[i].empty();
163
// table[i] = null;
164
// }
165
// else
166
// System.out.print ("leaf cache full");
167
// }
168
// else if (table[i] instanceof IDTableNodeBranch){
169
// if (branchCache.count() < MAX_CACHE_SIZE) {
170
// System.out.print ("branch cached");
171
// branchCache.pushTop (table[i]);
172
// table[i].empty();
173
// table[i] = null;
174
// }
175
// else
176
// System.out.print ("branch cache full");
177
// }
178
// else {
179
// throw new RuntimeException ("Unknown node type.");
180
// }
181
// }
182

183         super.deleteRequest(subTable);
184     }
185
186 }
187
Popular Tags