⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 idtable.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
字号:
// You can redistribute this software and/or modify it under the terms of
// the Ozone Library License version 1 published by ozone-db.org.
//
// The original code and portions created by SMB are
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
//
// $Id: IDTable.java,v 1.2 2004/01/09 23:43:05 per_nyfelt Exp $

package org.ozoneDB.core.storage.wizardStore;

import java.io.IOException;

import org.ozoneDB.DxLib.*;
import org.ozoneDB.core.Env;
import org.ozoneDB.core.ObjectID;
import org.ozoneDB.core.storage.ClusterID;
import org.ozoneDB.util.LogWriter;


/**
 * @author <a href="http://www.softwarebuero.de/">SMB</a>
 * @version $Revision: 1.2 $Date: 2004/01/09 23:43:05 $
 */
public final class IDTable extends DxDiskHashMap {

    final static long serialVersionUID = 1L;

    public final static int MAX_CACHE_SIZE = 2000;

    //    protected DxDeque		leafCache;
    //
    //    protected DxDeque		branchCache;
    //
    //    protected DxDeque		keyDataCache;


    public IDTable(String _baseFileName, int _maxBufferSize, int _cacheBits, int[] _tableBitSizes) {
        super(_baseFileName, _maxBufferSize, _cacheBits, _tableBitSizes);
        //        leafCache = new DxArrayDeque (MAX_CACHE_SIZE);
        //        branchCache = new DxArrayDeque (MAX_CACHE_SIZE);
        //        keyDataCache = new DxArrayDeque (MAX_CACHE_SIZE);
    }


    public synchronized void close() throws Exception {
        writeDirtyTables();
        setReusable(true);
    }


    public synchronized void writeDirtyTables() throws IOException {
        DxIterator it = buffer.iterator();
        DxDiskSubTable table = null;
        while ((table = (DxDiskSubTable) it.next()) != null) {
            if (table.isDirty()) {
                if (false) {
                    Env.currentEnv().logWriter.newEntry(this, "write dirty table: " + table.getFile(), LogWriter.DEBUG);
                }
                table.writeTable();
            }
        }
    }


    public boolean isDirtyTable(DxDiskSubTable table) {
        boolean result = table.isDirty();
        if (false) {
            Env.currentEnv().logWriter.newEntry(this, "isDirtyTable(): name=" + table.getFile() + ", dirty=" + result, LogWriter.DEBUG);
        }
        return result;
    }


    public void printStatistics() {
        Env.currentEnv().logWriter.newEntry(this, "Statistics:", LogWriter.INFO);
        Env.currentEnv().logWriter.newEntry(this, "    sub-table accesses: " + bufferAccesses + "  hits: " + bufferHits + " loads: " + (bufferAccesses - bufferHits), LogWriter.INFO);
        Env.currentEnv().logWriter.newEntry(this, "    cache accesses: " + cacheAccesses + "  hits: " + cacheHits, LogWriter.INFO);
    }


    public DxDiskHashNodeLeaf newNodeLeaf() {
        return new IDTableNodeLeaf(this);

        //        System.out.print ("newNodeLeaf()... ");
        //        if (leafCache.isEmpty()) {
        //            System.out.println ("new");
        //            return new IDTableNodeLeaf (this);
        //            }
        //        else {
        //            System.out.println ("cache");
        //            return (DxDiskHashNodeLeaf)leafCache.popTop();
        //            }
    }


    public DxDiskHashNodeBranch newNodeBranch() {
        return new IDTableNodeBranch(this);

        //        System.out.print ("newNodeBranch()... ");
        //        if (branchCache.isEmpty()) {
        //            System.out.println ("new");
        //            return new IDTableNodeBranch();
        //            }
        //        else {
        //            System.out.println ("cache");
        //            return (DxDiskHashNodeBranch)branchCache.popTop();
        //            }
    }


    public DxKeyData newKeyData() {
        return new DxKeyData();

        //        System.out.print ("newKeyData()... ");
        //        if (keyDataCache.isEmpty()) {
        //            System.out.println ("new");
        //            return new DxKeyData();
        //            }
        //        else {
        //            System.out.println ("cache");
        //            return (DxKeyData)keyDataCache.popTop();
        //            }
    }


    public ObjectID newObjectID() {
        //        System.out.println ("newObjectID()");
        return new ObjectID();
    }


    public ClusterID newClusterID() {
        //        System.out.println ("newClusterID()");
        return new ClusterID();
    }


    /**
     * The specified sub-table was deleted from the tree. So we have
     * to delete it from the table buffer too.
     */
    public synchronized void deleteRequest(DxDiskSubTable subTable) {
        //        System.out.println ("deleteRequest()");
        //
        //        DxDiskHashNode[] table = subTable.table();
        //        for (int i=0; i<table.length; i++) {
        //            if (table[i] instanceof IDTableNodeLeaf) {
        //                DxKeyData element = ((IDTableNodeLeaf)table[i]).element();
        //                while (element != null) {
        //                    if (keyDataCache.count() < MAX_CACHE_SIZE) {
        //                        System.out.print ("keydata cached");
        //                        keyDataCache.pushTop (element);
        //                        element = element.next;
        //                        }
        //                    else
        //                        System.out.print ("keydata cache full");
        //                    }
        //
        //                if (leafCache.count() < MAX_CACHE_SIZE) {
        //                    System.out.print ("leaf cached");
        //                    leafCache.pushTop (table[i]);
        //                    table[i].empty();
        //                    table[i] = null;
        //                    }
        //                else
        //                    System.out.print ("leaf cache full");
        //                }
        //            else  if (table[i] instanceof IDTableNodeBranch){
        //                if (branchCache.count() < MAX_CACHE_SIZE) {
        //                    System.out.print ("branch cached");
        //                    branchCache.pushTop (table[i]);
        //                    table[i].empty();
        //                    table[i] = null;
        //                    }
        //                else
        //                    System.out.print ("branch cache full");
        //                }
        //            else {
        //                throw new RuntimeException ("Unknown node type.");
        //                }
        //            }

        super.deleteRequest(subTable);
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -