亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? cache.java

?? Java寫的含有一個jdbc驅動的小型數(shù)據(jù)庫數(shù)據(jù)庫引擎
?? JAVA
字號:
/*
 * Cache.java
 *
 * Copyright (c) 2001, The HSQL Development Group
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 *
 * Neither the name of the HSQL Development Group nor the names of its
 * contributors may be used to endorse or promote products derived from this
 * software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * This package is based on HypersonicSQL, originally developed by Thomas Mueller.
 *
 */
package org.hsqldb;

import java.io.*;
import java.sql.*;

/**
 * Cache class declaration
 * <P>The cache class implements the handling of cached tables.
 *
 * @version 1.0.0.1
 * @see Row
 * @see CacheFree
 */
class Cache {
    private RandomAccessFile rFile;
    private final static int LENGTH = 1 << 14;
    private final static int MAX_CACHE_SIZE = LENGTH * 3 / 4;
    private Row		     rData[];
    private Row		     rWriter[];
    private Row		     rFirst;		   // must point to one of rData[]
    private Row		     rLastChecked;	   // can be any row
    private String	     sName;
    private final static int MASK = (LENGTH) - 1;
    private int		     iFreePos;
    private final static int FREE_POS_POS = 16;    // where iFreePos is saved
    private final static int INITIAL_FREE_POS = 32;
    private final static int MAX_FREE_COUNT = 1024;
    private CacheFree	     fRoot;
    private int		     iFreeCount;
    private int		     iCacheSize;

    /**
     * Cache constructor declaration
     * <P>The cache constructor sets up the initial parameters of the cache
     * object, setting the name used for the file, etc.
     *
     * @param name of database file
     */
    Cache(String name) {
	sName = name;
	rData = new Row[LENGTH];
	rWriter = new Row[LENGTH];
    }

    /**
     * open method declaration
     * <P>The open method creates or opens a database file.
     *
     * @param flag that indicates if this cache is readonly
     *
     * @throws SQLException
     */
    void open(boolean readonly) throws SQLException {
	try {
	    boolean exists = false;
	    File    f = new File(sName);

	    if (f.exists() && f.length() > FREE_POS_POS) {
		exists = true;
	    }

	    rFile = new RandomAccessFile(sName, readonly ? "r" : "rw");

	    if (exists) {
		rFile.seek(FREE_POS_POS);

		iFreePos = rFile.readInt();
	    } else {
		iFreePos = INITIAL_FREE_POS;
	    }
	} catch (Exception e) {
	    throw Trace.error(Trace.FILE_IO_ERROR,
			      "error " + e + " opening " + sName);
	}
    }

    /**
     * flush method declaration
     * <P>The flush method saves all cached data to the file, saves the free position
     * and closes the file.
     *
     * @throws SQLException
     */
    void flush() throws SQLException {
	try {
	    rFile.seek(FREE_POS_POS);
	    rFile.writeInt(iFreePos);
	    saveAll();
	    rFile.close();
	} catch (Exception e) {
	    throw Trace.error(Trace.FILE_IO_ERROR,
			      "error " + e + " closing " + sName);
	}
    }

    /**
     * shutdown method declaration
     * <P>the shutdown method closes the cache file.  It does not flush pending writes.
     *
     * @throws SQLException
     */
    void shutdown() throws SQLException {
	try {
	    rFile.close();
	} catch (Exception e) {
	    throw Trace.error(Trace.FILE_IO_ERROR,
			      "error " + e + " in shutdown " + sName);
	}
    }

    /**
     * free method declaration
     * <P>This method marks space in the database file as free.
	 * <P><B>Note: </B>If more than MAX_FREE_COUNT free positios then
	 * they are probably all are too small anyway; so we start a new list
	 * <P>todo: This is wrong when deleting lots of records
     *
     * @param r (Row object to be marked free)
     * @param pos (Offset in the file this Row was stored at)
     * @param length (Size of the Row object to free)
     *
     * @throws SQLException
     */
    void free(Row r, int pos, int length) throws SQLException {
	iFreeCount++;

	CacheFree n = new CacheFree();

	n.iPos = pos;
	n.iLength = length;

	if (iFreeCount > MAX_FREE_COUNT) {
	    iFreeCount = 0;
	} else {
	    n.fNext = fRoot;
	}

	fRoot = n;

	// it's possible to remove roots to
	remove(r);
    }

    /**
     * add method declaration
     * <P>This method adds a Row to the Cache.  It walks the
     * list of CacheFree objects to see if there is available space
     * to store the new Row, reusing space if it exists, otherwise
     * we grow the file.
     *
     * @param r (Row to be added to Cache)
     *
     * @throws SQLException
     */
    void add(Row r) throws SQLException {
	int       size = r.iSize;
	CacheFree f = fRoot;
	CacheFree last = null;
	int       i = iFreePos;

	while (f != null) {
	    if (Trace.TRACE) {
			Trace.stop();
	    }
		// first that is long enough
	    if (f.iLength >= size) {
		i = f.iPos;
		size = f.iLength - size;

		if (size < 8) {

		    // remove almost empty blocks
		    if (last == null) {
			fRoot = f.fNext;
		    } else {
			last.fNext = f.fNext;
		    }

		    iFreeCount--;
		} else {
		    f.iLength = size;
		    f.iPos += r.iSize;
		}

		break;
	    }

	    last = f;
	    f = f.fNext;
	}

	r.iPos = i;

	if (i == iFreePos) {
	    iFreePos += size;
	}

	int k = i & MASK;
	Row before = rData[k];

	if (before == null) {
	    before = rFirst;
	}

	r.insert(before);

	iCacheSize++;
	rData[k] = r;
	rFirst = r;
    }

    /**
     * getRow method declaration
     * <P>This method reads a Row object from the cache.
     *
     * @param pos (offset of the requested Row in the cache)
     * @param t (Table this Row belongs to)
     *
     * @return The Row Object as read from the cache.
     *
     * @throws SQLException
     */
    Row getRow(int pos, Table t) throws SQLException {
	int k = pos & MASK;
	Row r = rData[k];
	Row start = r;

	while (r != null) {
	    if (Trace.STOP) {
		Trace.stop();
	    }

	    int p = r.iPos;

	    if (p == pos) {
		return r;
	    } else if ((p & MASK) != k) {
		break;
	    }

	    r = r.rNext;

	    if (r == start) {
		break;
	    }
	}

	Row before = rData[k];

	if (before == null) {
	    before = rFirst;
	}

	try {
	    rFile.seek(pos);

	    int  size = rFile.readInt();
	    byte buffer[] = new byte[size];

	    rFile.read(buffer);

	    ByteArrayInputStream bin = new ByteArrayInputStream(buffer);
	    DataInputStream      in = new DataInputStream(bin);

	    r = new Row(t, in, pos, before);
	    r.iSize = size;
	} catch (IOException e) {
	    e.printStackTrace();

	    throw Trace.error(Trace.FILE_IO_ERROR, "reading: " + e);
	}

	// todo: copy & paste here
	iCacheSize++;
	rData[k] = r;
	rFirst = r;

	return r;
    }

    /**
     * cleanUp method declaration
     * <P>This method cleans up the cache when it grows too large. It works by
     * checking Rows in held in the Cache's iLastAccess member and removing
     * Rows that haven't been accessed in the longest time.
     *
     * @throws SQLException
     */
    void cleanUp() throws SQLException {
	if (iCacheSize < MAX_CACHE_SIZE) {
	    return;
	}

	int count = 0, j = 0;

	while (j++ < LENGTH && iCacheSize + LENGTH > MAX_CACHE_SIZE
	       && (count * 16) < LENGTH) {
	    if (Trace.STOP) {
		Trace.stop();
	    }

	    Row r = getWorst();

	    if (r == null) {
		return;
	    }

	    if (r.bChanged) {
		rWriter[count++] = r;
	    } else {

		// here we can't remove roots
		if (!r.canRemove()) {
		    remove(r);
		}
	    }
	}

	if (count != 0) {
	    saveSorted(count);
	}

	for (int i = 0; i < count; i++) {

	    // here we can't remove roots
	    Row r = rWriter[i];

	    if (!r.canRemove()) {
		remove(r);
	    }

	    rWriter[i] = null;
	}
    }

    /**
     * remove method declaration
     * <P>This method is used to remove Rows from the Cache. It is called
     * by the cleanUp method.
     *
     * @param r (Row to be removed)
     *
     * @throws SQLException
     */
    private void remove(Row r) throws SQLException {
	if (Trace.ASSERT) {
	    Trace.assert(!r.bChanged);

	    // make sure rLastChecked does not point to r
	}

	if (r == rLastChecked) {
	    rLastChecked = rLastChecked.rNext;

	    if (rLastChecked == r) {
		rLastChecked = null;
	    }
	}

	// make sure rData[k] does not point here
	int k = r.iPos & MASK;

	if (rData[k] == r) {
	    Row n = r.rNext;

	    rFirst = n;

	    if (n == r || (n.iPos & MASK) != k) {
		n = null;
	    }

	    rData[k] = n;
	}

	// make sure rFirst does not point here
	if (r == rFirst) {
	    rFirst = rFirst.rNext;

	    if (r == rFirst) {
		rFirst = null;
	    }
	}

	r.free();

	iCacheSize--;
    }

    /**
     * getWorst method declaration
     * <P>This method finds the Row with the smallest (oldest) iLastAccess member.
     * Called by the cleanup method.
     *
     * @return The selected Row Object
     *
     * @throws SQLException
     */
    private Row getWorst() throws SQLException {
	if (rLastChecked == null) {
	    rLastChecked = rFirst;
	}

	Row r = rLastChecked;

	if (r == null) {
	    return null;
	}

	Row candidate = r;
	int worst = Row.iCurrentAccess;

	// algorithm: check the next rows and take the worst
	for (int i = 0; i < 6; i++) {
	    int w = r.iLastAccess;

	    if (w < worst) {
		candidate = r;
		worst = w;
	    }

	    r = r.rNext;
	}

	rLastChecked = r.rNext;

	return candidate;
    }

    /**
     * Method declaration
     *
     *
     * @throws SQLException
     */
    private void saveAll() throws SQLException {
	if (rFirst == null) {
	    return;
	}

	Row r = rFirst;

	while (true) {
	    int count = 0;
	    Row begin = r;

	    do {
		if (Trace.STOP) {
		    Trace.stop();
		}

		if (r.bChanged) {
		    rWriter[count++] = r;
		}

		r = r.rNext;
	    } while (r != begin && count < LENGTH);

	    if (count == 0) {
		return;
	    }

	    saveSorted(count);

	    for (int i = 0; i < count; i++) {
		rWriter[i] = null;
	    }
	}
    }

    /**
     * Method declaration
     *
     *
     * @param count
     *
     * @throws SQLException
     */
    private void saveSorted(int count) throws SQLException {
	sort(rWriter, 0, count - 1);

	try {
	    for (int i = 0; i < count; i++) {
		rFile.seek(rWriter[i].iPos);
		rFile.write(rWriter[i].write());
	    }
	} catch (Exception e) {
	    throw Trace.error(Trace.FILE_IO_ERROR, "saveSorted " + e);
	}
    }

    /**
     * Method declaration
     *
     *
     * @param w
     * @param l
     * @param r
     *
     * @throws SQLException
     */
    private static final void sort(Row w[], int l,
				   int r) throws SQLException {
	int i, j, p;

	while (r - l > 10) {
	    i = (r + l) >> 1;

	    if (w[l].iPos > w[r].iPos) {
		swap(w, l, r);
	    }

	    if (w[i].iPos < w[l].iPos) {
		swap(w, l, i);
	    } else if (w[i].iPos > w[r].iPos) {
		swap(w, i, r);
	    }

	    j = r - 1;

	    swap(w, i, j);

	    p = w[j].iPos;
	    i = l;

	    while (true) {
		if (Trace.STOP) {
		    Trace.stop();
		}

		while (w[++i].iPos < p);

		while (w[--j].iPos > p);

		if (i >= j) {
		    break;
		}

		swap(w, i, j);
	    }

	    swap(w, i, r - 1);
	    sort(w, l, i - 1);

	    l = i + 1;
	}

	for (i = l + 1; i <= r; i++) {
	    if (Trace.STOP) {
		Trace.stop();
	    }

	    Row t = w[i];

	    for (j = i - 1; j >= l && w[j].iPos > t.iPos; j--) {
		w[j + 1] = w[j];
	    }

	    w[j + 1] = t;
	}
    }

    /**
     * Method declaration
     *
     *
     * @param w
     * @param a
     * @param b
     */
    private static void swap(Row w[], int a, int b) {
	Row t = w[a];

	w[a] = w[b];
	w[b] = t;
    }

}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产成人在线视频网站| 青青青伊人色综合久久| 国产一区美女在线| 欧美精品一区二区三区视频| 日本午夜精品视频在线观看| 在线成人高清不卡| 日韩av一级电影| 精品美女在线播放| 国产高清成人在线| 国产精品网友自拍| 色综合久久天天综合网| 一区二区三区在线观看欧美| 欧美日本在线视频| 美女视频黄 久久| 国产精品视频麻豆| 欧洲精品在线观看| 麻豆91小视频| 欧美国产综合一区二区| 91小视频免费观看| 亚洲高清三级视频| 2021久久国产精品不只是精品| 国产成人在线免费| 亚洲免费观看高清在线观看| 制服丝袜在线91| 国产高清精品网站| 亚洲一二三区不卡| 精品国产人成亚洲区| 99v久久综合狠狠综合久久| 亚洲第一av色| 久久精品欧美一区二区三区不卡 | 久久久九九九九| 99国产精品久久久久久久久久久| 一区二区三区久久| 欧美电影免费观看高清完整版 | 99久久精品国产一区二区三区 | hitomi一区二区三区精品| 亚洲综合一二三区| www国产精品av| 91蜜桃在线观看| 另类小说一区二区三区| 亚洲同性同志一二三专区| 7777精品伊人久久久大香线蕉经典版下载 | 亚洲一区二区av在线| 精品成人佐山爱一区二区| 日本精品视频一区二区| 麻豆成人免费电影| 亚洲午夜视频在线| 国产精品网站一区| 精品久久国产老人久久综合| 欧美伊人久久大香线蕉综合69| 国产在线视频不卡二| 亚洲成人综合视频| 亚洲欧美日韩国产综合在线| 欧美成人免费网站| 欧美日韩黄视频| 91麻豆精品秘密| 国产成人精品亚洲日本在线桃色| 日韩不卡一区二区三区| 亚洲精品乱码久久久久| 国产精品亲子伦对白| 欧美成人一区二区三区片免费 | 日韩一区二区三区电影| 一本一道波多野结衣一区二区| 国产精品538一区二区在线| 五月天中文字幕一区二区| 亚洲人成在线观看一区二区| 国产亚洲成av人在线观看导航 | 久久综合成人精品亚洲另类欧美 | 国产成人免费视| 国产剧情一区在线| 九色综合狠狠综合久久| 青青草成人在线观看| 午夜精品爽啪视频| 亚洲国产精品综合小说图片区| 中文字幕亚洲精品在线观看| 国产精品免费视频观看| 亚洲国产精品99久久久久久久久| 精品999在线播放| 欧美精品一区二区三区一线天视频| 欧美一区二区精品在线| 欧美一区二区在线不卡| 日韩欧美在线综合网| 日韩一区二区三区视频在线| 欧美精品1区2区| 欧美一区欧美二区| 欧美一区二区三区免费大片| 7777精品伊人久久久大香线蕉| 欧美精品99久久久**| 欧美精品色一区二区三区| 91精品国产全国免费观看| 欧美一级高清片在线观看| 欧美v日韩v国产v| 久久人人97超碰com| 国产婷婷色一区二区三区在线| 国产女人18毛片水真多成人如厕| 国产精品美女久久久久av爽李琼| 亚洲欧洲日韩av| 亚洲精品国产品国语在线app| 亚洲福利视频导航| 青草国产精品久久久久久| 国内偷窥港台综合视频在线播放| 国产成人免费av在线| 91丨porny丨中文| 欧美精品第1页| 亚洲精品一区二区三区福利| 中文字幕永久在线不卡| 亚洲自拍偷拍图区| 久久精品国内一区二区三区| 岛国一区二区三区| 在线观看日韩毛片| 欧美韩日一区二区三区| 一区二区三区高清在线| 麻豆精品国产传媒mv男同| 国产很黄免费观看久久| 日本精品视频一区二区三区| 6080yy午夜一二三区久久| 国产亚洲欧美一级| 亚洲成年人影院| 国产激情精品久久久第一区二区| 一本色道**综合亚洲精品蜜桃冫| 69堂亚洲精品首页| 国产日本一区二区| 亚洲电影一区二区| 国产福利一区二区| 欧美熟乱第一页| 国产视频911| 婷婷亚洲久悠悠色悠在线播放| 国产一区二区三区在线观看免费视频| av不卡免费在线观看| 欧美伦理电影网| 国产精品久久久久aaaa樱花| 卡一卡二国产精品| 色综合一个色综合| 久久久久久久久久久久电影 | 久久久久久久久久电影| 亚洲国产精品久久人人爱蜜臀 | 日韩国产高清在线| 国产ts人妖一区二区| 欧美久久一区二区| 中文乱码免费一区二区| 美女网站在线免费欧美精品| 色综合久久久久综合| 国产色综合久久| 精品亚洲国内自在自线福利| 欧美日韩不卡一区二区| 亚洲色图都市小说| 高清国产午夜精品久久久久久| 欧美一区中文字幕| 亚洲电影第三页| 91国偷自产一区二区三区成为亚洲经典| 精品国产凹凸成av人网站| 亚洲午夜在线视频| 色噜噜狠狠色综合中国| 国产日韩欧美综合在线| 韩国女主播一区| 欧美一区二区三区婷婷月色| 亚洲电影中文字幕在线观看| 91官网在线免费观看| 亚洲欧洲一区二区在线播放| 成人污污视频在线观看| 国产亚洲精久久久久久| 国产伦精一区二区三区| 精品日韩一区二区| 日本不卡一区二区三区高清视频| 欧美性猛交xxxxxx富婆| 亚洲狠狠丁香婷婷综合久久久| 99v久久综合狠狠综合久久| 国产精品久久久久影院老司| 不卡的av中国片| 国产精品国产自产拍高清av王其| 成人a免费在线看| **性色生活片久久毛片| 北条麻妃一区二区三区| 中文字幕在线不卡一区二区三区| 岛国av在线一区| 国产精品久久三区| 色一区在线观看| 亚洲乱码中文字幕综合| 91久久精品网| 亚洲v中文字幕| 日韩欧美精品三级| 国产永久精品大片wwwapp| 久久婷婷综合激情| 成人伦理片在线| 亚洲美女在线国产| 欧美日本国产视频| 麻豆精品精品国产自在97香蕉| 久久综合av免费| www.日韩精品| 亚洲国产精品久久不卡毛片| 欧美精品xxxxbbbb| 免费一级欧美片在线观看| 久久影院午夜片一区| 成人av先锋影音| 性欧美大战久久久久久久久| 欧美mv和日韩mv的网站| 成人黄色小视频在线观看| 一区二区成人在线观看| 91精品婷婷国产综合久久 | 久久丝袜美腿综合|