001: // You can redistribute this software and/or modify it under the terms of
002: // the Ozone Library License version 1 published by ozone-db.org.
003: //
004: // The original code and portions created by SMB are
005: // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
006: //
007: // $Id: IDTable.java,v 1.3 2002/06/08 00:49:39 mediumnet Exp $
008:
009: package org.ozoneDB.core.wizardStore;
010:
011: import java.io.*;
012: import org.ozoneDB.DxLib.*;
013: import org.ozoneDB.core.*;
014: import org.ozoneDB.util.LogWriter;
015:
016: /**
017: * @author <a href="http://www.softwarebuero.de/">SMB</a>
018: * @version $Revision: 1.3 $Date: 2002/06/08 00:49:39 $
019: */
020: public final class IDTable extends DxDiskHashMap {
021:
022: final static long serialVersionUID = 1L;
023:
024: public final static int MAX_CACHE_SIZE = 2000;
025:
026: // protected DxDeque leafCache;
027: //
028: // protected DxDeque branchCache;
029: //
030: // protected DxDeque keyDataCache;
031:
032: public IDTable(String _baseFileName, int _maxBufferSize,
033: int _cacheBits, int _tableBitSize) {
034: super (_baseFileName, _maxBufferSize, _cacheBits, _tableBitSize);
035: // leafCache = new DxArrayDeque (MAX_CACHE_SIZE);
036: // branchCache = new DxArrayDeque (MAX_CACHE_SIZE);
037: // keyDataCache = new DxArrayDeque (MAX_CACHE_SIZE);
038: }
039:
040: public synchronized void close() throws Exception {
041: writeDirtyTables();
042: setReusable(true);
043: }
044:
045: public synchronized void writeDirtyTables() throws IOException {
046: DxIterator it = buffer.iterator();
047: DxDiskSubTable table = null;
048: while ((table = (DxDiskSubTable) it.next()) != null) {
049: if (table.isDirty()) {
050: if (false) {
051: Env.currentEnv().logWriter.newEntry(this ,
052: "write dirty table: " + table.getFile(),
053: LogWriter.DEBUG);
054: }
055: table.writeTable();
056: }
057: }
058: }
059:
060: public boolean isDirtyTable(DxDiskSubTable table) {
061: boolean result = table.isDirty();
062: if (false) {
063: Env.currentEnv().logWriter.newEntry(this ,
064: "isDirtyTable(): name=" + table.getFile()
065: + ", dirty=" + result, LogWriter.DEBUG);
066: }
067: return result;
068: }
069:
070: public void printStatistics() {
071: Env.currentEnv().logWriter.newEntry(this , "Statistics:",
072: LogWriter.INFO);
073: Env.currentEnv().logWriter
074: .newEntry(this , " sub-table accesses: "
075: + bufferAccesses + " hits: " + bufferHits
076: + " loads: " + (bufferAccesses - bufferHits),
077: LogWriter.INFO);
078: Env.currentEnv().logWriter.newEntry(this ,
079: " cache accesses: " + cacheAccesses + " hits: "
080: + cacheHits, LogWriter.INFO);
081: }
082:
083: public DxDiskHashNodeLeaf newNodeLeaf() {
084: return new IDTableNodeLeaf(this );
085:
086: // System.out.print ("newNodeLeaf()... ");
087: // if (leafCache.isEmpty()) {
088: // System.out.println ("new");
089: // return new IDTableNodeLeaf (this);
090: // }
091: // else {
092: // System.out.println ("cache");
093: // return (DxDiskHashNodeLeaf)leafCache.popTop();
094: // }
095: }
096:
097: public DxDiskHashNodeBranch newNodeBranch() {
098: return new IDTableNodeBranch(this );
099:
100: // System.out.print ("newNodeBranch()... ");
101: // if (branchCache.isEmpty()) {
102: // System.out.println ("new");
103: // return new IDTableNodeBranch();
104: // }
105: // else {
106: // System.out.println ("cache");
107: // return (DxDiskHashNodeBranch)branchCache.popTop();
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: public ObjectID newObjectID() {
126: // System.out.println ("newObjectID()");
127: return new ObjectID();
128: }
129:
130: public ClusterID newClusterID() {
131: // System.out.println ("newClusterID()");
132: return new ClusterID();
133: }
134:
135: /**
136: * The specified sub-table was deleted from the tree. So we have
137: * to delete it from the table buffer too.
138: */
139: public synchronized void deleteRequest(DxDiskSubTable subTable) {
140: // System.out.println ("deleteRequest()");
141: //
142: // DxDiskHashNode[] table = subTable.table();
143: // for (int i=0; i<table.length; i++) {
144: // if (table[i] instanceof IDTableNodeLeaf) {
145: // DxKeyData element = ((IDTableNodeLeaf)table[i]).element();
146: // while (element != null) {
147: // if (keyDataCache.count() < MAX_CACHE_SIZE) {
148: // System.out.print ("keydata cached");
149: // keyDataCache.pushTop (element);
150: // element = element.next;
151: // }
152: // else
153: // System.out.print ("keydata cache full");
154: // }
155: //
156: // if (leafCache.count() < MAX_CACHE_SIZE) {
157: // System.out.print ("leaf cached");
158: // leafCache.pushTop (table[i]);
159: // table[i].empty();
160: // table[i] = null;
161: // }
162: // else
163: // System.out.print ("leaf cache full");
164: // }
165: // else if (table[i] instanceof IDTableNodeBranch){
166: // if (branchCache.count() < MAX_CACHE_SIZE) {
167: // System.out.print ("branch cached");
168: // branchCache.pushTop (table[i]);
169: // table[i].empty();
170: // table[i] = null;
171: // }
172: // else
173: // System.out.print ("branch cache full");
174: // }
175: // else {
176: // throw new RuntimeException ("Unknown node type.");
177: // }
178: // }
179:
180: super.deleteRequest(subTable);
181: }
182:
183: }
|