📄 storeimpl.java
字号:
/* =============================================================
* SmallSQL : a free Java DBMS library for the Java(tm) platform
* =============================================================
*
* (C) Copyright 2004-2007, by Volker Berlin.
*
* Project Info: http://www.smallsql.de/
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* ---------------
* StoreImpl.java
* ---------------
* Author: Volker Berlin
*
*/
package smallsql.database;
import java.io.*;
import java.sql.SQLException;
public class StoreImpl extends Store {
private static final int DEFAULT_PAGE_SIZE = 8192; // 8 Kb
private static final int PAGE_MAGIC = 0x12DD13DE; // are used for repairing a table
/**
* The structure of the Page Control Block is:
* 4 byte - page magic
* 4 Byte - Status 0:normal; 1:deleted; 2:Pointer to an update; 3: updated page
* 4 Byte - used size of the page
* 4 byte - physical size of the page
* 4 byte - offset to the next page
* 8 byte - position of an updated page
*/
private static final int PAGE_CONTROL_SIZE = 28;
private static final byte[] page_control = new byte[PAGE_CONTROL_SIZE];
private int status; // valid value are follow:
private static final int NORMAL = 0;
private static final int DELETED = 1;
/**
* Using of UPDATE_POINTER and UPDATED_PAGE
* If a page are updated and the new data are larger as the old data then
* the old page are changed to a UPDATE_POINTER. The new page is
* a UPDATED_PAGE. On reading the pages only the UPDATE_POINTER is read.
* The UPDATED_PAGE are skipped. Thats a row change not it position.
*/
private static final int UPDATE_POINTER = 2;
private static final int UPDATED_PAGE = 3;
final private Table table;
private byte[] page; // Data of one page
private StorePage storePage;
private long filePos; // Position in the file
private int sizeUsed;
private int sizePhysical;
private int nextPageOffset;
private long filePosUpdated;
private int type;
private StoreImpl updatePointer;
private StoreImpl( Table table, StorePage storePage, int type, long filePos ){
this.table = table;
this.storePage = storePage;
this.filePos = filePos;
this.type = type;
}
/** folgende Arten von StoreImpl Types sind m鰃lich
INSERT: Eine Page die neue Daten enthalten wird. filePos ist noch nicht spezifiziert.
CREATE: Eine spezielle Art von INSERT.
SELECT: Nur Leseoperationen sind m鰃lich.
UPDATE: Hat eine filePos, wenn neue gr鲞e zu klein, mu
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -